In timer.php I have this:
$handle = fopen( 'php://stdout', 'wa' ) ;
$unusedEvTimerObject = new EvTimer(0, 1, function ($watchercallback) use ($handle) { //create & call timer
echo "=>".(Ev::iteration() % 60)."<=";
fwrite( $handle, "Hello World! \n");
} );
Ev::run();
fclose( $handle );
And in child.php I have this:
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/error-output.txt", "a")
);
$process = proc_open('php ', $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], "<? include('app/timer.php'); ?>");
fclose($pipes[0]);
$output = "";
while (!feof($pipes[1])) {
$output .= fgets($pipes[1]);
};
fclose($pipes[1]);
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
If I invoke timer.php direct with
$php app/timer.php
the output I get is "=>1<=Hello World! =>2<=Hello World!"
but if I invoke with $php app/child.php I get no output whereas I'd expect stdout from timer.php to redirect to child.php and be printed by it.
I'm flailing a bit & I'm guessing child.php is not getting any input but I can't see why. HALP!
The $output isn't printed in the sample code.
while (!feof($pipes[1])) {
echo fgets($pipes[1]);
};
Calling $> php child.php then prints the timer output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With