ID: 48683
Comment by: php at richardneill dot org
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 explanation. I agree - I had misunderstood the
docs, and PHP is behaving correctly.
Previous Comments:
[2009-06-25 08:37:28] sjoerd-php at linuxonly dot nl
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.
[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
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