note 109604 added to function.popen
| From: | thuejk at gmail dot com | Date: | Wed, 01 Aug 2012 13:02:26 +0000 |
| Subject: | note 109604 added to function.popen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189561@lists.php.net to get a copy of this message | ||
fread is blocking on streams from popen.
That means that if you do
$stream = popen("tail -f myfile");
fread($stream, 100);
then fread will only return full chunks of 100 characters. So if the size of myfile isn't a
multiple of 100, the last chunk will not be returned.
This is documented in https://bugs.php.net/bug.php?id=51056 . Some people
in that bug discussion argue that this should be kept to not change behaviour, but example #3 on http://dk.php.net/fread clearly says "When reading from
anything that is not a regular local file, such as streams returned when reading remote files or
from popen() and fsockopen(), reading will stop after a packet is available."
A workaround is to call
stream_set_blocking($stream, 0);
on the stream you get from popen().
----
Server IP: 195.184.96.15
Probable Submitter: 95.166.216.227
----
Manual Page -- http://www.php.net/manual/en/function.popen.php
Edit -- https://master.php.net/note/edit/109604
Del: integrated -- https://master.php.net/note/delete/109604/integrated
Del: useless -- https://master.php.net/note/delete/109604/useless
Del: bad code -- https://master.php.net/note/delete/109604/bad+code
Del: spam -- https://master.php.net/note/delete/109604/spam
Del: non-english -- https://master.php.net/note/delete/109604/non-english
Del: in docs -- https://master.php.net/note/delete/109604/in+docs
Del: other reasons-- https://master.php.net/note/delete/109604
Reject -- https://master.php.net/note/reject/109604
Search -- https://master.php.net/manage/user-notes.php