基于 GatewayWorker 的常驻 WebSocket 服务 · 所有命令在框架根目录执行
composer require usualtool/ut-workerman
安装后即可用框架自带的 workerman 命令启动服务。
ut-workerman/src/Events.php —— 负责所有业务逻辑,开发者在此进行逻辑处理。gatewayclient/Gateway.php —— 提供所有业务接口,通过 use GatewayClient\Gateway; 调用。use GatewayClient\Gateway;
Gateway::sendToAll($msg); // 广播
Gateway::sendToUid($uid, $msg); // 定向推送
192.168.0.1:1025 → 自动注册服务 127.0.0.1:1025,并额外创建 WebSocket 服务 127.0.0.1:1026。
| 操作 | 命令 | 参数 |
|---|---|---|
| 默认启动 | php usualtool workerman start 内网IP:端口 | 必须带 |
| 守护启动 | php usualtool workerman start -d 内网IP:端口 | 必须带 |
| 停止进程 | php usualtool workerman stop | 前台模式 |
| 停止进程 | php usualtool workerman stop 内网IP:端口 | 守护模式 |
| 强制重启 | php usualtool workerman restart 内网IP:端口 | 必须带 |
| 平滑重启 | php usualtool workerman reload | 无需参数 |
| 查看状态 | php usualtool workerman status | 无需参数 |
php usualtool workerman start 内网IP:端口
# 例:
php usualtool workerman start 192.168.0.1:1025
php usualtool workerman start -d 内网IP:端口
# 例:
php usualtool workerman start -d 192.168.0.1:1025
守护启动命令参数与默认启动一样,区别在于 start 后增加了参数 -d。
# 默认启动模式
Ctrl + C
php usualtool workerman stop
# 守护启动模式
php usualtool workerman stop 192.168.0.1:1025
php usualtool workerman restart 内网IP:端口
# 例:
php usualtool workerman restart 192.168.0.1:1025
php usualtool workerman reload
服务在启动的情况下才能平滑重启,适用于只改业务代码(Events.php)的场景。
php usualtool workerman status
始于2018年,UT框架版权归原作者所有
开放、包容、发展。
工单 |
团队 |
蜀ICP备2024067013号