webman/push统计在线人数问题https://www.workerman.net/webman

邹意

问题描述

比如说当前有3个用户在应用中是属于在线的情况,当我这时候stop停止项目,然后在启动项目,最后这3个用户都关闭应用离线了,而这时候我统计在线用户的话这3个用户就始终一直在线起的,无法正常离线。

当我打印 $result['result']['channels'] 就一直有这三个用户
经过各种测试,好像必须要所有用户离线的时候重启才不出现此情况,或者说有用户在线的时候就不能stop,只能通过reload平滑重启也不会出现此情况

$api = new Api(
    str_replace('0.0.0.0', '127.0.0.1', config('plugin.webman.push.app.api')),
    config('plugin.webman.push.app.app_key'),
    config('plugin.webman.push.app.app_secret')
);
$result = $api->get('/channels', ['filter_by_prefix' => 'user-line-']);
if ($result || $result['status'] == 200) {
    $user_line_ids = []; //在线用户的id
    foreach ($result['result']['channels'] as $k => $v) {
        $user_line_ids[] = intval(ltrim($k,'user-line-'));
    }
}
278 1 2
1个回答

walkor

执行 php start.php connections 能看到连接情况

  • 邹意 2024-05-31

    查看到里面只有 一个 websocket的连接,应该是我的统计大屏,但是大屏还是显示有用户在线(应该没得才对),大屏显示的在线人数实际就是$result['result']['channels'] 的总数量是不可能有错的呀

×
🔝