2011-02-08 76 views
0

我在执行ssh脚本输出到浏览器时遇到问题,而不是最终执行它。在处理冗长的脚本时php-capture控制台输出

脚本编写:

$descriptorspec = array(
     0 => array("pipe","r"), 
     1 => array("pipe","w"), 
     2 => array("file","./error.log","a") 
) ; 
$cwd = 'path/path1' ; 
for($counter=1;$counter<= 10;$counter++) 
{ 
     $cmd="sudo test.sh arg1 arg2 arg3"; 
     $process = proc_open('ssh [email protected]', $descriptorspec, $pipes, $cwd) ; 
     if (is_resource($process)) 
     { 
      fwrite($pipes[0], $cmd) ; 
     fclose($pipes[0]) ; 
       echo stream_get_contents($pipes[1]) ; 
        fclose($pipes[1]) ; 
       $return_value = proc_close($process); 
      echo "$counter=command returned $return_value<br>"; 
     } 
} 

shell脚本需要10分钟来执行。如果$ counter = 10,则花费太多时间才能获得屏幕上显示的实际输出。我要求它在执行时持续显示流输出,以便我们知道发生了什么。 是否有缓冲的情况?

回答

0

尝试flush() function

+1

谢谢。你的意思是说 - echo stream_get_contents($ pipes [1]); flush(); – rahul 2011-02-08 12:20:47