exeoutput for php,在PHP中运行带有实时输出的进程

这是一种显示shell命令实时输出的好方法:

header("Content-type: text/plain");

// tell php to automatically flush after every output

// including lines of output produced by shell commands

disable_ob();

$command = 'rsync -avz /your/directory1 /your/directory2';

system($command);

您将需要此功能来防止输出缓冲:

function disable_ob() {

// Turn off output buffering

ini_set('output_buffering', 'off');

// Turn off PHP output compression

ini_set('zlib.output_compression', false);

// Implicitly flush the buffer(s)

ini_set('implicit_flush', true);

ob_implicit_flush(true);

// Clear, and turn off output buffering

while (ob_get_level() > 0) {

// Get the curent level

$level = ob_get_level();

// End the buffering

ob_end_clean();

// If the current level has not changed, abort

if (ob_get_level() == $level) break;

}

// Disable apache output buffering/compression

if (function_exists('apache_setenv')) {

apache_setenv('no-gzip', '1');

apache_setenv('dont-vary', '1');

}

}

不过,它在我尝试过的每台服务器上都不起作用,我希望我能提供一些建议,告诉你在PHP配置中应该寻找什么,以确定你是否应该在尝试让这种行为在你的服务器上起作用时拔出头发!还有人知道吗?

下面是纯PHP中的一个虚拟示例:

header("Content-type: text/plain");

disable_ob();

for($i=0;$i<10;$i++)

{

echo $i . "\n";

usleep(300000);

}

我希望这能帮助那些在谷歌上搜索过的人。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值