src/Leevel/Protocol/WebsocketServer.php
public function onWebsocketClose(SwooleWebsocketServer $server, int $fd, int $reactorId): void
    {
        $this->log(
            sprintf('Server close, fd %d, reactorId %d.', $fd, $reactorId)
        );

        /**
         * 未连接
         * WEBSOCKET_STATUS_CONNECTION = 1，连接进入等待握手
         * WEBSOCKET_STATUS_HANDSHAKE = 2，正在握手
         * WEBSOCKET_STATUS_FRAME = 3，已握手成功等待浏览器发送数据帧.
         *
         * @see https://wiki.swoole.com/wiki/page/413.html
         */
        $clientInfo = $this->server->getClientInfo($fd);

        if ($clientInfo['websocket_status'] <= 0) {
            return;
        }

        // 不存在任何连接
        if (!$this->count()) {
            return;
        }

        if (false === ($pathInfo = $this->getClientPathInfo($fd))) {
            return;
        }

        $request = $this->createRequestWithPathInfo($pathInfo, self::CLOSE);

        $this->setPreRequestMatched($request, [$server, $fd, $reactorId]);

        $response = $this->dispatchRouter($request);
    }
public function onWebsocketClose(SwooleWebsocketServer $server, int $fd, int $reactorId): void
    {
        $this->log(
            sprintf('Server close, fd %d, reactorId %d.', $fd, $reactorId)
        );

        /**
         * 未连接
         * WEBSOCKET_STATUS_CONNECTION = 1，连接进入等待握手
         * WEBSOCKET_STATUS_HANDSHAKE = 2，正在握手
         * WEBSOCKET_STATUS_FRAME = 3，已握手成功等待浏览器发送数据帧.
         *
         * @see https://wiki.swoole.com/wiki/page/413.html
         */
        $clientInfo = $this->server->getClientInfo($fd);

        if ($clientInfo['websocket_status'] <= 0) {
            return;
        }

        // 不存在任何连接
        if (!$this->count()) {
            return;
        }

        if (false === ($pathInfo = $this->getClientPathInfo($fd))) {
            return;
        }

        $request = $this->createRequestWithPathInfo($pathInfo, self::CLOSE);

        $this->setPreRequestMatched($request, [$server, $fd, $reactorId]);

        $response = $this->dispatchRouter($request);
    }
监听连接关闭事件
每个浏览器连接关闭时执行一次, reload 时连接不会断开, 也就不会触发该事件.

@param \Swoole\Websocket\Server $server
@param int                      $fd
@param int                      $reactorId

@see https://wiki.swoole.com/wiki/page/p-event/onClose.html