easyswoole的websocket获取客户端信息

唐默
2023-12-01

easyswoole的websocket获取连接信息,端口,fd,ip,错误等等。

{"websocket_status":3,"server_port":9502,"server_fd":3,"socket_fd":36,"socket_type":1,"remote_port":56692,"remote_ip":"127.0.0.1","reactor_id":0,"connect_time":1606985399,"last_time":1606986742,"close_errno":0}

遍历当前的websocket链接:

public static function foreachAllClient()
{
    $server = ServerManager::getInstance()->getSwooleServer();
    $start_fd = 0;
    while (true) {
        $conn_list = $server->getClientList($start_fd, 10);
        if ($conn_list === false or count($conn_list) === 0) {
            echo "finish\n";
            break;
        }
        $start_fd = end($conn_list);
        // dumps($conn_list);
        foreach ($conn_list as $fd) {
            $server->push($fd, "broadcast");
        }
    }
}
 类似资料: