在vendor/thinkphp/topthink/think-swoole/src/websocket/socketio/Handler.php的onOpen方法中修改代码:
public function onOpen($fd, Request $request)
{
$this->eio = $request->param('EIO');
$payload = json_encode(
[
'sid' => base64_encode(uniqid()),
'upgrades' => [],
'pingInterval' => $this->pingInterval,
'pingTimeout' => $this->pingTimeout,
]
);
$this->push(EnginePacket::open($payload));
$this->event->trigger("swoole.websocket.Open", $request);
if ($this->eio < 4) {
// 注释此处,tcp连接一直存在,会导致占用大量内存并不建议此操作
// $this->resetPingTimeout($this->pingInterval + $this->pingTimeout);
$this->onConnect();
} else {
$this->schedulePing();
}
}