Edit report at http://bugs.php.net/bug.php?id=54717&edit=1
ID: 54717 Updated by: cataphr...@php.net Reported by: wuschba at yahoo dot de -Summary: stream_set_timeout and popen don't work together +Summary: stream_set_timeout doesn't work for STDIO streams Status: Open -Type: Bug +Type: Feature/Change Request Package: Streams related Operating System: Linux PHP Version: 5.3.6 Block user comment: N Private report: N New Comment: I can't reproduce this for stream_set_blocking -- it works as expected: <?php $proc = popen("tail -f /var/log/syslog &", "r"); if (!stream_set_blocking($proc, 0)) print "stream_set_blocking has failed\n"; else print "stream_set_blocking successful\n"; $readfds = array($proc); $writefds = $exceptfds = array(); /* in non-blocking mode, if we don't wait for data with this select, the fread will return nothing and the process will close before tail can write the data, resulting in "tail: write error: Broken pipe" This is expected and shows the non-blocking mode is working */ if (stream_select($readfds, $writefds, $exceptfds, 1)) echo fread($proc, 8192); If it still doesn't work for you, please add more information (e.g. an actual script we can run). For stream_set_timeout, it's true it doesn't work, the read timeout is implemented only for sockets (and user space wrappers). Implementing this for the plain wrapper is risky and the return is small because it can be accomplished in userspace by using non-blocking mode and stream_select. It would imply changing the stream to non-blocking upon each read operation and enforcing the timeout ourselves, like we do for sockets. This makes things less efficient and adds complexity to the code, which leads to bugs (e.g. there was a busy waiting bug in ssl code until the last release), not to mention it would imply completely different code for windows. I'm reclassifying it as a feature request, but don't hold your breath. Previous Comments: ------------------------------------------------------------------------ [2011-05-12 11:23:20] wuschba at yahoo dot de Description: ------------ --- >From manual page: http://www.php.net/function.stream-set-timeout#Changelog --- When open a stream with popen or proc_open, stream_set_timeout or stream_ set_ blocking fail (tested on Linux and Windows), while the manual says: "As of PHP 4.3, this function can (potentially) work on any kind of stream." (while 'potentially' of course might mean everything ;-)) Test script: --------------- $proc[0] = popen("/usr/srv/php /my/folder/myscript.php 0 &", "r"); $proc[1] = popen("/usr/srv/php /my/folder/myscript.php 1 &", "r"); if (!stream_set_timeout($proc[0], 1, 0)) print "stream_set_timeout failed on stream 1"; if (!stream_set_timeout($proc[1], 1, 0)) print "stream_set_timeout failed on stream 2"; Expected result: ---------------- It should NOT output: stream_set_timeout failed on stream 1 stream_set_timeout failed on stream 2 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54717&edit=1