|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-04-10 12:38 UTC] sniper@php.net
[2007-07-17 13:30 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
Description: ------------ Opening a TCP stream, and attempting to access in a non-blocking matter results in fread continuing to block. Reproduce code: --------------- <?php $socket = stream_socket_server('tcp://0.0.0.0:3838'); stream_set_blocking($socket, 0); $conns = array(); $text = ""; while(true){ $new_connection = @stream_socket_accept($socket, 0); print "T"; if(!$new_connection) sleep(1); else { stream_set_blocking($new_connection,0); $conns[] = $new_connection; unset($new_connection); } foreach($conns as $k=>$c) $text .= fread($conns[$k], 8192); foreach($conns as $c) fwrite($c,$text); $text = ""; } ?> Expected result: ---------------- After connecting once or more (with telnet or similar), the program should still tick (will print 'T' to console). Actual result: -------------- Once 1 or more connections are established, the fread blocks, and prevents the program from iterating (or printing 'T' to the console). It will iterate after data is received from all connections.