测试中发现 favicon.ico 也触发了请求,
但是好奇的是 为什么 favicon.ico 会触发了两次请求?
$server = new swoole_websocket_server("0.0.0.0", 8812);
$server->set(
[
'enable_static_handler' => true,
'document_root' => '/usr/local/myweb/web4/data',
]
);
//监听websocket连接打开事件
$server->on('open', 'onOpen');
function onOpen(swoole_websocket_server $server, $request)
{
print_r($request->fd);
}
//监听websocket消息事件
$server->on('message', function (swoole_websocket_server $server, $frame) {
echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
$server->push($frame->fd, "push data test!");
});
$server->on('close', function ($ser, $fd) {
echo "client {$fd} closed\n";
});
$server->start();
请求的url(单单请求了这个不存在的ico):
服务端触发: