There are quite a few bad streams usages there.
I'd rewrite your code like this:
$words = fopen('/usr/share/dict/words', 'r');
stream_copy_to_stream($words, $pipes[0]);
fclose($pipes[0]);
fclose($words);
$output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
My guess at the cause of the problem was that you're tying to write
2MB into a pipe, and the underlying write() syscall could only write
64k; since you're ignoring the return code from fwrite(), you're
missing this vital fact.
Using the streams functions in PHP 5 helps you to write code that
"does what I mean", and makes for shorter, more readable code.
--Wez.
PS: http://netevil.org/talks/PHP-Streams-Lucky-Dip.pdf
has some tips and insider knowledge on using streams in PHP.
On 1/23/06, Mark Krenz <[EMAIL PROTECTED]> wrote:
> 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";
> }
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php