#36796 [Asn->Csd]: Streams blocking after set non-blocking
| From: | jani@php.net | Date: | Tue, 17 Jul 2007 13:30:06 +0000 |
| Subject: | #36796 [Asn->Csd]: Streams blocking after set non-blocking | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115142@lists.php.net to get a copy of this message | ||
ID: 36796
Updated by: jani@php.net
Reported By: seufert at gmail dot com
-Status: Assigned
+Status: Closed
Bug Type: Streams related
Operating System: AMD64 Linux 2.6 (Debian)
PHP Version: 5.1.2
-Assigned To: wez
+Assigned To: jani
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2006-04-10 12:38:03] sniper@php.net
Wez, here's another one.
------------------------------------------------------------------------
[2006-03-20 06:37:39] seufert at gmail dot com
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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36796&edit=1