合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# open\_websocket\_close\_frame 启用websocket协议中关闭帧(opcode为0x08的帧)在onMessage回调中接收,默认为false。 开启后,可在WebSocketServer中的`onMessage`回调中接收到客户端或服务端发送的关闭帧,开发者可自行对其进行处理。 示例: ~~~ $server = new swoole_websocket_server("0.0.0.0", 9501); $server->set(array("open_websocket_close_frame" => true)); $server->on('open', function (swoole_websocket_server $server, $request) {}); $server->on('message', function (swoole_websocket_server $server, $frame) { if ($frame->opcode == 0x08) { echo "Close frame received: Code {$frame->code} Reason {$frame->reason}\n"; } else { echo "Message received: {$frame->data}\n"; } }); $server->on('close', function ($ser, $fd) {}); $server->start(); ~~~