当前位置:  开发笔记 > 编程语言 > 正文

swoole 的server.php全局变量数据只能放两个?

一直只有两个开了四个客户端了。。。{代码}

一直只有两个

开了四个客户端了。。。

push($fd, $msg);
        }
    }
}

// 监听WebSocket连接打开事件
$ws->on('open', function (swoole_websocket_server $ws, $request) use(&$fds) {
    $fds[$request->fd] = $request->fd;
    $ws->push($request->fd, "欢迎接入小孟聊天平台\n");
    broadcast($ws, "用户{$request->fd}登录啦!", $fds, $request->fd);
    var_dump($fds);
});

// 监听WebSocket消息事件
$ws->on('message', function (swoole_websocket_server $ws, $frame) use(&$fds) {
    $msg =  'from'.$frame->fd.":{$frame->data}\n";
    broadcast($ws, $msg, $fds, $frame->fd);
   // $ws->push($frame->fd, "server: {$frame->data}");
    // $ws->push($frame->fd, "server: {$frame->data}");
});

// 监听WebSocket连接关闭事件
$ws->on('close', function (swoole_websocket_server $ws, $fd) use(&$fds) {
    unset($fds[$fd]);
    broadcast($ws, "用户{$fd}下线啦!", $fds);
});


$ws->start();

回复内容:

一直只有两个

开了四个客户端了。。。

push($fd, $msg);
        }
    }
}

// 监听WebSocket连接打开事件
$ws->on('open', function (swoole_websocket_server $ws, $request) use(&$fds) {
    $fds[$request->fd] = $request->fd;
    $ws->push($request->fd, "欢迎接入小孟聊天平台\n");
    broadcast($ws, "用户{$request->fd}登录啦!", $fds, $request->fd);
    var_dump($fds);
});

// 监听WebSocket消息事件
$ws->on('message', function (swoole_websocket_server $ws, $frame) use(&$fds) {
    $msg =  'from'.$frame->fd.":{$frame->data}\n";
    broadcast($ws, $msg, $fds, $frame->fd);
   // $ws->push($frame->fd, "server: {$frame->data}");
    // $ws->push($frame->fd, "server: {$frame->data}");
});

// 监听WebSocket连接关闭事件
$ws->on('close', function (swoole_websocket_server $ws, $fd) use(&$fds) {
    unset($fds[$fd]);
    broadcast($ws, "用户{$fd}下线啦!", $fds);
});


$ws->start();
推荐阅读
TXCWB_523
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有