Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing old php websocket

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?

like image 692
anonymousfox Avatar asked Jun 11 '26 05:06

anonymousfox


1 Answers

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.

like image 146
Jon Heather Avatar answered Jun 14 '26 10:06

Jon Heather



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!