I am using PHP-Websockets to create a simple chat server. I have everything working correctly when I run the php script that creates the websocket on my server for the first time. If the script stops for some reason and I try to rerun it, I get an error saying that the script could not bind the socket because it already exists.
How can I make a script to find this old socket (given that I know which port it is running on) and close it so I can make a new connection?
If you have shell access, I would use the following command to deduce the PID of the process using that socket (port).
netstat --tcp --listening --program
Then kill that process.
kill %pid%
To prevent this from happening though, I would double check that your script terminates gracefully and closes the socket first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With