php fgets stream timeout
i am working on a server-client terminal chat using php. i wanted to know if there are any ways to detect if the client did not entered anything for like 5 or 10 seconds. using fgets pauses the开发者_如何学Python terminal and waits for each entry thus making the chat not realtime xD
i am still sort of modifying the code i got from here http://codeyoung.blogspot.com/2009/07/simple-php-socket-based-terminal-chat.html
thank you :D
based on quarry's answer ..i tried
while(true) {
stream_set_timeout($sock,1);
$reply = fread($sock, 4086);
if($reply != ""){ echo "[Server] ".$reply; }
stream_set_timeout($uin,1);
$resp = fgets($uin);
if($resp != ""){ fwrite($sock, $resp); }
}
but the set timeout doesn't seem to work any solutions?
this is not doable unless PHP supports multi-threading .what i did is use two terminals. one for receiving the messages and another for sending
精彩评论