在timer.php中我有如下代码:
$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 );
child。php中是:
$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";
}
如果我用
直接调用timer.php$php app/timer.php
我得到的输出是"=>1<=Hello World!=> 2 & lt; =你好世界!"
,但如果我调用$php app/child.php我没有得到任何输出,而我希望从timer.php的标准输出重定向到child.php并由它打印。
我有点发抖&我猜child。php没有得到任何输入,但我不知道为什么。想买!
示例代码中没有打印$输出。
while (!feof($pipes[1])) {
echo fgets($pipes[1]);
};
调用$> php child.php然后打印定时器输出