Gateway类的onClose回调偶发无法获取uid属性

IT男

问题描述

在webman项目中使用了Gateway-worker,在process.php的gateway.constructor中添加了onClose回调,在回调里面获取uid属性,出现偶尔无法获取该属性的报错,然后整个项目程序卡住,接口全部处于pending

程序代码

config\plugin\webman\gateway-worker\process.php部分代码如下:

'gateway' => [
    'handler'     => Gateway::class,
    'listen'      => 'websocket://0.0.0.0:7777',
    'count'       => 2,
    'reloadable'  => false,
    'constructor' => ['config' => [
        'lanIp'           => '127.0.0.1',
        'startPort'       => 2300,
        'pingInterval'    => 25,
        'pingData'        => '{"type":"ping"}',
        'registerAddress' => '127.0.0.1:1212',
        'onConnect'       => function($gateway){
            // print_r($gateway);
        },
        'onClose' => function ($gateway){
            // 发布事件
            Event::dispatch('gateway.close', $gateway);
        }
        ]]
    ]

config\event.php部分代码如下

'gateway.close' => [
    [app\controller\UserController::class, 'wsClose'],
    [app\controller\AdminController::class, 'wsClose'],
]

app\controller\UserController.php部分代码如下:

public function wsClose($gateway){
    print_r($gateway->uid);
}

app\controller\AdminController.php部分代码如下:

public function wsClose($gateway){
    print_r($gateway->uid);
}

报错信息

Undefined property: Workerman\Connection\TcpConnection::$uidErrorException: Undefined property: Workerman\Connection\TcpConnection::$uid

操作系统及workerman/webman等框架组件具体版本

window10系统
"workerman/webman-framework": "^2.1",
"webman/gateway-worker": "^1.0",

111 1 0
1个回答

你是怎么保证TcpConnection::$uid一定就会存在的?

  • IT男 7天前

    已经解决了,多处调用就一定会出现这个问题,单次调用就不会

🔝