First of all I want to apologize if my english is not perfect because i'm not a native english.
I'm facing something that I find weird using stream socket in php; I wanted to run some sort of webserver locally (I know it's not the best way to do it but just for learning).
I'm using this code in my terminal :
<?php
$server = stream_socket_server("tcp://0.0.0.0:8200");
while ($conn = stream_socket_accept($server)) {
echo fread($conn, 1000);
fputs($conn, "HTTP/1.1 200 OK
Server: PHPserver
bonjour");
usleep(10000);
fclose($conn);
}
fclose($server);
?>
This works well, I've read that instead of fread I should use stream_socket_recvfrom. But my question is : is if I remove the usleep(10000); this doesn't work anymore my browser sends me an error with ERR_CONNECTION_RESET, but I don't understand why, I think somehow my terminal is closing something to quick ? If someone knows in detail I would be glad to know.
Thanks :)