php-capture console output while processing a lengthy script
开发者_StackOverflow社区I have an issue on capturing the ssh script output onto the browser as it executes rather than having it in the end.
Script written:
$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 user@server', $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 script takes 10mins to execute. If the $counter=10 then it taking too much time to get the real output thrown on screen. I require that it keeping on showing the stream output as it executes so that we know what's happening. Is there case of buffering?
Try the flush() function.
精彩评论