ID: 48683 Comment by: sjoerd-php at linuxonly dot nl Reported By: php at richardneill dot org Status: Open Bug Type: Streams related Operating System: Linux PHP Version: 5.2CVS-2009-06-25 (snap) New Comment:
Thank you for your bug report. In your code example, you use /dev/null as blocking file. However, this is not entirely correct. As you say, /dev/null gives EOF immediately, which means stream_select sees it as ready: "The streams listed in the read array will be watched to see if characters become available for reading (more precisely, to see if a read will not block - in particular, a stream resource is also ready on end-of-file, in which case an fread() will return a zero length string)." In your loop, fread() constantly read a empty string and the file resource is constantly ready. Maybe this information already solves your problem. If it does not, please provide a better code example. Previous Comments: ------------------------------------------------------------------------ [2009-06-25 04:15:01] php at richardneill dot org Description: ------------ It seems that stream_select is failing to return 0 even if all of the streams would block. I've tested the code below on multiple versions of PHP from 5.2.4 upward, and get the same result on them all. (It's possible I've misunderstood the requirements for sockets, but I've quintuple-checked this code.) Reproduce code: --------------- #!/usr/bin/php <? echo "This should never print 'did fread'.\n"; echo "It should just print 'stream_select returned 0' every second\n"; echo "\n"; $fp=fopen("/dev/null",r); #open /dev/null for reading. #Should immediately result in EOF. while (true) { $r = array($fp); $n = stream_select($r, $w = null, $e = null, 1); #stream select on read array, timeout 1 sec echo "stream_select returned $n\n"; if ($n) { #Try to read up to 1024 bytes echo fread($fp,1024); echo "did fread.\n"; } usleep (100000); //slow down (0.1s) } ?> Expected result: ---------------- I expect to see the line stream_select returned 0 repeated every 1 second. Actual result: -------------- I get repeated instances of: stream_select returned 1 did fread. fread is returning nothing, but still the stream_select insists that there is data available to be read! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48683&edit=1