ID:               20180
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-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] [EMAIL PROTECTED]

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

Reply via email to