Php 在DIV中显示shell输出

Php 在DIV中显示shell输出,php,jquery,ajax,html,Php,Jquery,Ajax,Html,如果我在php页面中运行此代码,则会在web页面上以单行形式获得输出。每一行在生成输出时显示。这很好,是我所期望的 do.php $order = array("\r\n", "\n", "\r"); $a = popen('rsyncd -Pav remote.server.com::files/file1.tar.gz localfile.tar.gz', 'r'); while($b = fgets($a, 64)) { ob_flush();flush();

如果我在php页面中运行此代码,则会在web页面上以单行形式获得输出。每一行在生成输出时显示。这很好,是我所期望的

do.php

$order   = array("\r\n", "\n", "\r");
$a = popen('rsyncd -Pav remote.server.com::files/file1.tar.gz localfile.tar.gz', 'r');

while($b = fgets($a, 64)) {
    ob_flush();flush();
        $update = str_replace($order,'<br />', $b);
        echo $update;
    ob_flush();flush();
}
pclose($a);
我得到的是:

receiving file list ... <br />2����+$��g��A���

*/�/IU040RH�,I-VP(JMLQ04���

M����!<���d�6��

*�/I�Q(άJU�,V0741214�TP(.HMM)-  Z��YBt��ⲷ��<ũ٢ 
正在接收文件列表
2����+$��G��A.��� */�/IU040RH�,I-VP(JMLQ04���
M����!这可能会有帮助:谢谢-更新原始帖子
receiving file list ...

1 file to consider

wrote 102 bytes  read 119 bytes  442.00 bytes/sec

total size is 71424169  speedup is 323186.29  
receiving file list ... <br />2����+$��g��A���

*/�/IU040RH�,I-VP(JMLQ04���

M����!<���d�6��

*�/I�Q(άJU�,V0741214�TP(.HMM)-  Z��YBt��ⲷ��<ũ٢ 
<script type="text/javascript">
        var last_response_len = false;
        $.ajax('./flushed-ajax.php', {
            xhrFields: {
                onprogress: function(e)
                {
                    var this_response, response = e.currentTarget.response;
                    if(last_response_len === false)
                    {
                        this_response = response;
                        last_response_len = response.length;
                    }
                    else
                    {
                        this_response = response.substring(last_response_len);
                        last_response_len = response.length;
                    }
                    console.log(this_response);
                }
            }
        })
        .done(function(data)
        {
            console.log('Complete response = ' + data);
        })
        .fail(function(data)
        {
            console.log('Error: ', data);
        });
        console.log('Request Sent');
        </script>