You are here: proc_open and buffer limit? « PHP « IT news, forums, messages
proc_open and buffer limit?

Posted by Mark Krenz on 01/22/06 02:25

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/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация