$gateway->onConnect = function ($connection) {
//二进制
$connection->websocketType = Workerman\Protocols\Websocket::BINARY_TYPE_ARRAYBUFFER;
//鉴权
$connection->onWebSocketConnect = function ($connection, $http_header) {
// 可以在这里判断连接来源是否合法,不合法就关掉连接
// $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
//if ($_SERVER['HTTP_ORIGIN'] != 'http://localhost:5173') {
// var_dump('非法连接,已自动关闭');
// $connection->close();
//}
// onWebSocketConnect 里面$_GET $_SERVER是可用的
//var_dump($_GET, $_SERVER);
};
};