Php Websocket在Firefox上运行良好,但在Chrome上不起作用

Php Websocket在Firefox上运行良好,但在Chrome上不起作用,php,google-chrome,firefox,amazon-web-services,websocket,Php,Google Chrome,Firefox,Amazon Web Services,Websocket,我已经在aws ec2中使用php套接字设置了一个websocket服务器,使用我的dns作为ws-url,如: var websocket=newwebsocket('ws://ec2-177-71-x-x.sa-east-1.compute.amazonaws.com:60997') 以下是firefox控制台中的请求: Host: ec2-177-71-x-x.sa-east-1.compute.amazonaws.com:60997 User-Agent: Mozilla/5.0 (X1

我已经在aws ec2中使用php套接字设置了一个websocket服务器,使用我的dns作为ws-url,如:

var websocket=newwebsocket('ws://ec2-177-71-x-x.sa-east-1.compute.amazonaws.com:60997')

以下是firefox控制台中的请求:

Host: ec2-177-71-x-x.sa-east-1.compute.amazonaws.com:60997
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://localhost
Sec-WebSocket-Key: csxgGFmTuJYxgvfsbgKtyA==
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
答复如下:

Connection: "Upgrade"
Sec-WebSocket-Accept: "AmwLLFdVkE9buCccH1oggz4FNJM="
Upgrade: "websocket"
WebSocket-Location: "ws://ec2-177-71-x-x.sa-east-1.compute.amazonaws.com:60997"
WebSocket-Origin: "ec2-177-71-x-x.sa-east-1.compute.amazonaws.com"
谷歌Chrome似乎无法访问websocket服务器,我试着输入url,但只有firefox可以连接

我想问题可能是握手,这是我正在使用的函数

//handshake new client.
function perform_handshaking($receved_header,$client_conn, $host, $port)
{
    var_dump($receved_header);
    $headers = array();
    $lines = preg_split("/\r\n/", $receved_header);
    foreach($lines as $line)
    {
        $line = chop($line);
        if(preg_match('/\A(\S+): (.*)\z/', $line, $matches))
        {
            $headers[$matches[1]] = $matches[2];
        }
    }

    $secKey = $headers['Sec-WebSocket-Key'];

    $secAccept = base64_encode(pack('H*', sha1($secKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
    //hand shaking header
    $upgrade  = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" .
    "Upgrade: websocket\r\n" .
    "Connection: Upgrade\r\n" .
    "WebSocket-Origin: $host\r\n" .
    "WebSocket-Location: ws://$host:$port\r\n".
    "Sec-WebSocket-Accept:$secAccept\r\n\r\n";
    var_dump(socket_write($client_conn,$upgrade,strlen($upgrade)));
}
附加信息:我在本地和测试服务器中都设置了相同的websocket,它是一台Centos 6.0机器,使用PHP5.4+,在chrome和firefox中都运行良好。
出现问题的生产服务器中的php版本是:php 5.3.27

问题已解决:Squid不支持协议升级websocket连接代理,如果websocket失败,firefox将尝试进行协议连接