var_dump($upgrade);, но после соединение разрываеться.
<?php
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
$address = '127.0.0.1';
$port = 8000;
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
echo "Socket create...";
socket_bind($sock, $address, $port);
socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1);
echo "Socket bind...";
socket_listen($sock);
echo "Socket listen...";
while ($newSock = socket_accept($sock)) {
echo "Socket accept...";
$header = socket_read($newSock, 1024);
echo "Socket read...";
if (preg_match('/Sec-WebSocket-Key: (.*)/', $header, $match)) {
$SecWebSocketAccept = base64_encode(pack('H*', sha1($match[1] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
$upgrade = "101 Switching Protocols\r\n" .
"Upgrade: websocket\r\n" .
"Connection: Upgrade\r\n" .
"Sec-WebSocket-Accept: $SecWebSocketAccept\r\n\r\n";
var_dump($upgrade);
socket_write($newSock, $upgrade, strlen($upgrade));
}
}