$gateway->router偶現(xiàn)取不到值的情況,導(dǎo)致服務(wù)異常退出
//指定 WebsocketBusinessWorker
$gateway->router = function ($worker_connections, $client_connection) {
$connection_names = [];
foreach ($worker_connections as $key => $worker_connection) {
$values = explode(':', $key);
if ($values[1] == 'WebsocketBusinessWorker') {
$connection_names[$values[2]] = $key;
}
}
if (!count($connection_names)) {
return null;
}
$key = $connection_names[mt_rand(0, count($connection_names) - 1)];
empty($client_connection->businessworker_address) && $client_connection->businessworker_address = $key;
return $worker_connections[$client_connection->businessworker_address];
};