WebSocket giving creation error

2

I'm having trouble, when trying to run the websocket, it returns me the following error in the image

ThecodeI'musingisthis:

<?php$ip='localhost';$porta=8080;//-------------------------------$servidor=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);socket_set_option($servidor,SOL_SOCKET,SO_REUSEADDR,1);socket_bind($servidor,$ip,$porta);socket_listen($servidor);$cliente=socket_accept($servidor);//--------------------------------$pedido=socket_read($cliente,5000);preg_match('#Sec-WebSocket-Key:(.*)\r\n#',$pedido,$matches);$key=base64_encode(pack('H*',sha1($matches[1].'258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));$headers="HTTP/1.1 101 Switching Protocols\r\n";
$headers .= "Upgrade: websocket\r\n";
$headers .= "Connection: Upgrade\r\n";
$headers .= "Sec-WebSocket-Version: 13\r\n";
$headers .= "Sec-WebSocket-Accept: $key\r\n\r\n";
socket_write($cliente, $headers, strlen($headers));
// mensagem
while (true) {
    sleep(1);
    $content = 'horas: ' . time();
    $response = chr(129) . chr(strlen($content)) . $content;
    socket_write($cliente, $response);
}
?>

Note: I'm trying to learn to use it alone kkk

    
asked by anonymous 26.06.2018 / 22:06

1 answer

2

It seems like a shame, but I forgot to enable the "extension = sockets" in PHP.ini, after I took the semicolon and restarted the apache server, it worked normally.

    
26.06.2018 / 23:22