PHP websocket在safari、headers和modyfication上不起作用

PHP websocket在safari、headers和modyfication上不起作用,php,jquery,websocket,phpwebsocket,Php,Jquery,Websocket,Phpwebsocket,我使用下面的源代码执行带有绘图的web套接字 我能够运行在FF和chrome浏览器中工作的脚本,但在safari中不工作。据我所知,这可能与safari中使用的握手有关,与FF和chrome中使用的握手不同 在SocketServer.php类中,我发现了以下规则: $headers = $this->parseRequestHeader($buffer); if (isset($headers['Sec-WebSocket-Key'])) { $key = $headers['

我使用下面的源代码执行带有绘图的web套接字

我能够运行在FF和chrome浏览器中工作的脚本,但在safari中不工作。据我所知,这可能与safari中使用的握手有关,与FF和chrome中使用的握手不同

在SocketServer.php类中,我发现了以下规则:

$headers = $this->parseRequestHeader($buffer);

if (isset($headers['Sec-WebSocket-Key'])) {
    $key = $headers['Sec-WebSocket-Key'];
} else {
    $key = $headers['Sec-WebSocket-Key1'];
}
$hash = base64_encode(
        sha1($key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)
);
/在ff和chrome的标题中存在Sec-WebSocket键,safari有Sec-WebSocket-Key1和Sec-WebSocket-Key2/

if (isset($headers['Sec-WebSocket-Key'])) {
    $headers = array(
        'HTTP/1.1 101 Switching Protocols',
        'Upgrade: websocket',
        'Connection: Upgrade',
        'Sec-WebSocket-Accept: ' . $hash
    );
} else {
    $headers = array(
        "HTTP/1.1 101 Web Socket Protocol Handshake",
        "Upgrade: WebSocket",
        "Connection: Upgrade",
        "WebSocket-Origin: http://localhost",
        "WebSocket-Location: ws://localhost:9300",
    );
}

$headers = implode("\r\n", $headers) . "\r\n\r\n";
$left = strlen($headers);

do {
    $sent = @socket_send($this->socket, $headers, $left, 0);

    if ($sent === false) {
        $error = $this->server->getLastError();

        throw new Exception(
                'Sending handshake failed: : ' . $error->message .
                ' [' . $error->code . ']'
        );
    }

    $left -= $sent;

    if ($sent > 0) {
        $headers = substr($headers, $sent);
    }
} while ($left > 0);

$this->state = self::STATE_OPEN;
}

我试图改变safari的标题,但是没有效果。Safari同时连接我和断开连接-我认为问题是由这些标题引起的,我不知道如何定制它们以正确的方式工作。
有人知道如何修改代码以支持safari和其他浏览器吗

看起来WebSocket服务器已经9个月没有更新了。因此,我建议您考虑另一种PHP WebSocket解决方案,例如正在积极开发的解决方案。

在whcih vesrion中,您可以在这里看到讨论