合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# 启动与停止 注意Workerman启动停止等命令都是在命令行中完成的。 要启动Workerman,首先需要有一个启动入口文件,里面定义了服务监听的端口及协议。可以参考[入门指引--简单开发实例部分](https://www.workerman.net/doc/workerman/getting-started/simple-example.html) 这里以[workerman-chat](https://www.workerman.net/workerman-chat)为例,它的启动入口为start.php。 ### 启动 以debug(调试)方式启动 `php start.php start` 以daemon(守护进程)方式启动 `php start.php start -d` ### 停止 `php start.php stop` ### 重启 `php start.php restart` ### 平滑重启 `php start.php reload` ### 查看状态 `php start.php status` ### 查看连接状态(需要Workerman版本>=3.5.0) `php start.php connections` ### **端口被占用** ``` sudo netstat -tuln | grep 2347 ``` ![](https://img.kancloud.cn/88/96/88962587be738d46a7dc47e75950f78d_533x36.png) **上面的没有显示进程用下面的** ~~~ sudo lsof -i :2347 ~~~ ![](https://img.kancloud.cn/43/44/4344df7bc1f5d5ad823637a4df85b37b_569x51.png) **下面的命令还可以查看该进程的执行文件** ``` ls -l /proc/17533/exe ``` ![](https://img.kancloud.cn/f8/17/f8170efef9fe562c38de905c3c338051_601x36.png) ``` sudo ss -ltnp | grep :2347 ``` ![](https://img.kancloud.cn/11/4e/114e04eaa561b810e1036541c4a434bc_789x39.png) ``` ps -p 17533 -o args= ``` ![](https://img.kancloud.cn/41/06/410645fcf1c51bcc5a07f3d801bc51f9_476x33.png) ## **杀掉进程** ~~~ sudo kill -9 <PID> ~~~ ``` sudo kill -9 17533 ``` ``` ps aux | grep workerman ``` ![](https://img.kancloud.cn/93/9f/939ffb96439cb4903dcab2cfc35e4f1a_657x33.png) ~~~ telnet 8.111.110.115 2347 telnet 8.137.80.185 2347 ~~~ [centOS7 firewalld防火墙操作命令\_centos 刷新防火墙-CSDN博客](https://blog.csdn.net/jianyue0420/article/details/125317933) ``` #重新刷新防火墙配置 不断开连接 firewall-cmd --reload #重新刷新防火墙配置 断开所有连接 类似重启 firewall-cmd --complete-reload ``` ## debug和daemon方式区别 1、以debug方式启动,代码中echo、var\_dump、print等打印函数会直接输出在终端。 2、以daemon方式启动,代码中echo、var\_dump、print等打印会默认重定向到/dev/null文件,可以通过设置`Worker::$stdoutFile = '/your/path/file';`来设置这个文件路径。 3、以debug方式启动,终端关闭后workerman会随之关闭并退出。 4、以daemon方式启动,终端关闭后workerman继续后台正常运行。 ## 什么是平滑重启? 参见[平滑重启原理](https://www.workerman.net/doc/workerman/faq/reload-principle.html)