问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/13931101/closing-old-php-websocket