proc_open and buffer limit?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 I'm using PHP 5.1.1 on Apache 2.0.54 on Gentoo Linux.  I've been trying
to write a program to pass information to a program using proc_open,
however when I do, it only passes the first 65536 bytes of the stream
and then cuts off the rest.  To make sure its not the program I'm trying
to send to, I tries using /bin/cat instead and get the same problem.

Below, I've included the code that I'm using, which for the most part is
from the proc_open documentation page.  For testing, I'm reading from a
word dictionary which is over 2MB in size. Is there something I'm
missing about using proc_open?

-------------------------------------------------------------------------
$program = "/bin/cat";

$descriptorspec = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w"),
   2 => array("file", "/tmp/error-output.txt", "a")
);

$cwd = '/var/www';
$env = array('HOME' => '/var/www');

$process = proc_open($program, $descriptorspec, $pipes, $cwd, $env);

if (is_resource($process)) {

    stream_set_blocking($pipes[0], FALSE);
    stream_set_blocking($pipes[1], FALSE);

    $handle = fopen("/usr/share/dict/words", "r");
    while (!feof($handle)) {
        $input .= fread($handle, 8192);
    }
    
    fwrite($pipes[0], $input);
    fclose($handle);
    fclose($pipes[0]);

    while (!feof($pipes[1])) {
       $output .= fgets($pipes[1], 8192);
    }
    fclose($pipes[1]);

     print "<PRE>$output</PRE><BR><BR>\n";

    $return_value = proc_close($process);

    echo "command returned $return_value\n";
}
-------------------------------------------------------------------------



-- 
Mark S. Krenz
IT Director
Suso Technology Services, Inc.
http://suso.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux