Closing old php websocket

喜夏-厌秋 提交于 2019-12-11 03:26:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!