#20180 [Opn->Fbk]: can only read 4096 bytes of stdout from proc_open

From: Date: Thu, 31 Oct 2002 14:33:49 +0000
Subject: #20180 [Opn->Fbk]: can only read 4096 bytes of stdout from proc_open
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-23788@lists.php.net to get a copy of this message
 ID:               20180
 Updated by:       wez@php.net
 Reported By:      kims@contrail.com.au
-Status:           Open
+Status:           Feedback
 Bug Type:         Apache2 related
 Operating System: Debian GNU/Linux
 PHP Version:      4CVS-2002-10-30
 New Comment:

Could you strace your test script under apache?
(run http with the -X option to prevent it forking).
Also, it would be helpful if you could try it with apache 1
and compare results.



Previous Comments:
------------------------------------------------------------------------

[2002-10-30 22:10:31] kims@contrail.com.au

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 this bug report at http://bugs.php.net/?id=20180&edit=1



Thread (5 messages)

« previous php.bugs (#23788) next »