在webman項目中使用了Gateway-worker,在process.php的gateway.constructor中添加了onClose回調(diào),在回調(diào)里面獲取uid屬性,出現(xiàn)偶爾無法獲取該屬性的報錯,然后整個項目程序卡住,接口全部處于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){
// 發(fā)布事件
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
window10系統(tǒng)
"workerman/webman-framework": "^2.1",
"webman/gateway-worker": "^1.0",