note 50408 added to function.popen
| From: | shaun at nospam dot phplabs dot com | Date: | Sun, 27 Feb 2005 13:52:21 +0000 |
| Subject: | note 50408 added to function.popen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85637@lists.php.net to get a copy of this message | ||
Note that there appears to be a limit to the amount of data that fread() will return from a handle
opened with popen(). A call to fread() may not return as much as you ask for.
For example, suppose I have a file "myfile.txt" which is more than 10KB in size. The
following code works as expected:
<?php
$fp = fopen('myfile.txt', 'r');
$data = fread($fp, 10240);
echo strlen($data);
?>
The output is '10240.' However, popen() behaves differently:
<?php
$fp = popen('/bin/cat myfile.txt', 'r');
$data = fread($fp, 10240);
echo strlen($data);
?>
On my system, this code prints out '8192' instead of the expected '10240.'
----
Manual Page -- http://www.php.net/manual/en/function.popen.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50408
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50408&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50408&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50408&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50408&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50408&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50408&report=yes
Search -- http://master.php.net/manage/user-notes.php