2015-07-19 18 views
6

在timer.php我有這樣的:在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應用程序/ timer.php

輸出我得到直接的就是「=> 1 < =的Hello World!=> 2 < = Hello World!「

但是如果我用$ php app/child.php調用 我沒有輸出,而我期望從timer.php輸出stdout重定向到child.php並由它打印。

我揮舞了一下&我猜child.php沒有得到任何輸入,但我不明白爲什麼。 HALP!

+1

你可以嘗試捕捉在子文件緩存中的所有輸出,然後在最後輸出它 –

回答

1

$輸出不會打印在示例代碼中。

while (!feof($pipes[1])) { 
    echo fgets($pipes[1]); 
}; 

調用$> PHP child.php然後打印定時器輸出

相關問題