From: [EMAIL PROTECTED]
Operating system: Debian GNU/Linux
PHP version: 4CVS-2002-10-30
PHP Bug Type: Apache2 related
Bug description: can only read 4096 bytes of stdout from proc_open
When using proc_open() with a set of pipes to read the output of a process,
only the first 4096 bytes of the pipe are read when using PHP under
Apache.
When running the same script using php-cgi on the command line, the
complete output is returned.
Hence, this seems to be an PHP/Apache problem, although admittedly it
could be a proc_open() or fread() problem, or an apache2 problem.
I'm using the latest apache2 debs from Debian unstable on ppc.
Here is a script that reproduces the problem for me. It creates a
tempfile, writes more than 4096 bytes of data to it, then tries to read it
all back via a pipe from /bin/cat (run with proc_open).
<?
header('Content-type: text/plain');
$path = "/tmp/foo";
# data to write to temporary file
$data = "foo";
# beef up the size of data so it's > 4096 bytes
for ($i = 0; $i < 16; $i++)
$data .= $data;
# write the data to the file
$fh = fopen($path, "w");
fwrite($fh, $data);
fclose($fh);
# set up a process using proc_open to cat the file to stdout
$proc = proc_open(
'cat /tmp/foo',
array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
),
$pipes
);
# read data from cat's stdout into $out
while (!feof($pipes[1]))
$out .= fread($pipes[1], 1024);
# number of bytes read successfully
echo "read: " . strlen($out) . " bytes.\n";
# check if this represents the whole file
if (strlen($out) != strlen($data))
echo "didn't read all " . strlen($data) . " bytes of file.\n";
# close pipes from proc_open
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
# close process
proc_close($proc);
# delete temp file
unlink($path);
?>
output from php-cgi:
Status: 200
X-Powered-By: PHP/4.3.0-dev
Content-type: text/plain
read: 196608 bytes.
output when run via apache:
read: 4096 bytes.
didn't read all 196608 bytes of file.
--
Edit bug report at http://bugs.php.net/?id=20180&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=20180&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=20180&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=20180&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=20180&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=20180&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=20180&r=support
Expected behavior: http://bugs.php.net/fix.php?id=20180&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=20180&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=20180&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=20180&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20180&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=20180&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=20180&r=isapi