php proc_open不会立即向浏览器发送输出

时间:2013-07-10 05:34:50

标签: php

我正在使用带有proc_open的php脚本在浏览器上立即获得shell输出。 这项工作在cli但不是通过网络 这是我的剧本:

//$arr_pipes = array( );

$str_command = './something.sh';


$descriptorspec = array(

    0 => array("pipe", "r"),  // stdin
    1 => array("pipe", "w"),  // stdout -> we use this
    2 => array("pipe", "w")   // stderr 

);

//   0 => array( "file", "php://stdin", "r" ),   // stdin is a file that the child will read from
//   1 => array( "file", "php://stdout", "w" ),  // stdout is a file that the child will write to
//   2 => array( "file", "/dev/null", "w" )      // stderr is a file that the child will write to



$process = @proc_open( $str_command, $descriptorspec, $pipes );
//$process = proc_open( $str_command, $descriptorspec, $arr_pipes);



if ( is_resource( $process ) )

{

 while( ! feof($pipes[1]))

    {
        $return_message = fgets($pipes[1], 1024);
        if (strlen($return_message) == 0) break;
        echo "<pre>$return_message</pre>";
    }

}


?>

0 个答案:

没有答案