在PHP中,我无法从一个进程管道到另一个进程

Dav*_*idH 6 php pipe timer

在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 );
Run Code Online (Sandbox Code Playgroud)

在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";
}
Run Code Online (Sandbox Code Playgroud)

如果我直接调用timer.php

$ php app/timer.php

我得到的输出是"=> 1 <= Hello World!=> 2 <= Hello World!"

但是如果我用$ php app/child.php调用我没有输出,而我希望来自timer.php的stdout重定向到child.php并由它打印.

我有点fla&&我猜猜child.php没有得到任何输入,但我不明白为什么.HALP!

Jas*_*dry 1

示例代码中未打印 $output。

while (!feof($pipes[1])) {
    echo fgets($pipes[1]);
};
Run Code Online (Sandbox Code Playgroud)

调用 $> php child.php 然后打印计时器输出