关闭旧的PHP websocket [英] Closing old php websocket

查看:270
本文介绍了关闭旧的PHP websocket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP-Websockets 创建一个简单的聊天服务器.第一次运行在我的服务器上创建websocket的php脚本时,我一切正常.如果脚本由于某种原因而停止运行,而我尝试重新运行它,则会收到一条错误消息,指出该脚本无法绑定套接字,因为该脚本已经存在.

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?

推荐答案

如果您具有shell访问权限,则可以使用以下命令来推断使用该套接字(端口)的进程的PID.

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

然后杀死该进程.

kill %pid%

不过,为防止这种情况发生,我会仔细检查您的脚本是否正常终止并首先关闭套接字.

To prevent this from happening though, I would double check that your script terminates gracefully and closes the socket first.

这篇关于关闭旧的PHP websocket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆