Workerman 作为ws 客户端场景 重启/重载的不能正常断开的处理方法

xuntee

当前遇到 woekerman 作为ws客户端
workman重启或重载 对方ws服务端cpu100%
用js 自带websocket 连接 刷新网页对端 cpu正常
后来抓包发现 重启或重载时 没有正确发送 断开ws的 package opcode=0x8

onWorkerStop $worker2->connections 是空的
所以有了下面的方法
仅供参考
如你有更优解 请告知 谢谢

$worker->onWorkerStart = function (Worker $worker) {
    $events = new Events();
    $con = new AsyncTcpConnection('ws://127.0.0.1:8080/socket');

    $con->onConnect    = array($events, 'onConnect');
    $con->onMessage    = array($events, 'onMessage');
    $con->onClose    = array($events, 'onClose');
    $con->onWebSocketClose    = array($events, 'onWebSocketClose');
    $con->onWebSocketConnect    = array($events, 'onWebSocketConnect');
    //重启 发送断开指令 opcode 0x8
    Worker::$globalEvent->add(\SIGINT, EventInterface::EV_SIGNAL, function () use ($con) {
        $con->send(\pack('H*', '88800a0c5cde'), true);
    });
    //重载 发送断开指令 opcode 0x8
    Worker::$globalEvent->add(\SIGUSR1, EventInterface::EV_SIGNAL, function () use ($con) {
        $con->send(\pack('H*', '88800a0c5cde'), true);//
    });

    $con->connect();
};
998 0 0
0个评论

xuntee

330
积分
0
获赞数
0
粉丝数
2022-07-21 加入
🔝