在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
window10系统
"workerman/webman-framework": "^2.1",
"webman/gateway-worker": "^1.0",
你是怎么保证
TcpConnection::$uid
一定就会存在的?已经解决了,多处调用就一定会出现这个问题,单次调用就不会