1

从命令行:

sudo -u apache php -r 'exec("rsync -avi --rsh=\"ssh -o StrictHostKeyChecking=no -p22\" --omit-dir-times /var/www/html/ test@out:/var/www/html/ 2>&1", $a, $n);print_r($a);';

返回这个(我想要这样的输出):

 Array
(
    [0] => sending incremental file list
    [1] => <f+++++++++ testrsync
    [2] =>
    [3] => sent 9143 bytes  received 47 bytes  18380.00 bytes/sec
    [4] => total size is 25642011  speedup is 2790.21
)

但来自 Apache2:

exec("rsync -avi --rsh=\"ssh -o StrictHostKeyChecking=no -p22\" --omit-dir-times /var/www/html/ test@out:/var/www/html/ 2>&1", $a, $n);
print_r($a);

我得到这个输出:

array (
  0 => 'sending incremental file list',
  1 => ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '',
  312 => 'sent 139318 bytes  received 183398 bytes  215144.00 bytes/sec',
  313 => 'total size is 25642011  speedup is 79.46',
)

在测试之前,我从终端和浏览器中删除了 testrsync文件,rsync 成功传输了 testrsync文件,但在 apache2 中它没有显示这一行:

<f+++++++++ testrsync

我想在浏览器中通过 Rsync 获取修改文件的列表。

Apache/2.2.15、PHP 5.4.20、Centos 6.4

4

2 回答 2

1

您可以将该文件(使用 php 标头)保存为.txt 而不是 html 或 php。在浏览器中不会发生任何形成

于 2013-10-03T12:42:29.047 回答
0

发现问题:

Rsync 输出如下所示:

[1] => <f..t...... logo-1.png

[2] => <f..t...... logo.png

并且浏览器将 < 解析为新标签,因此我得到空输出,但源代码显示完整输出。我花了一个多小时调试它;D

于 2013-10-03T12:06:52.880 回答