php implicit flush,PHP ob_implicit_flush 用法 手册 | 示例代码

这篇博客讨论了PHP中的ob_implicit_flush函数在Linux环境下不按预期工作的问题,特别是在命令行脚本中的表现。在PHP 4.3.3之前的版本以及PHP 5 beta1中,该函数在命令行环境中无法实现预期的flush效果,所有输出会在脚本结束时一次性发送。作者提供了一个使用ob_end_flush和ob_flush作为工作绕过的示例代码。这个信息对于遇到类似问题的PHP开发者来说是很有帮助的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

######### BEWARE ##########

There is a bug (or at least an unexpected feature of ob_implicit_flush) that has been already discussed on the PHP bugtracker :

Code like this WILL NOT work :

// This will not work as expected on Linux.

ob_implicit_flush (1);

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

echo "grrrrrrrrrrn";

sleep(1);

}

?>

This feature happens on Linux versions of PHP, in all versions of php4 prior to 4.3.3 (don't know yet for the next ones) but also in php5 beta1. ob_implicit_flush has NO EFFECT on command-line (console, CLI) scripts, no flushing at all will be made, all output will be sent at the end of the script.

There is a workaround using ob_end_flush() and ob_flush, here it is :

// This works !

ob_end_flush();

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

echo "yeah :-))))n";

@ob_flush();

sleep(1);

}

?>

hope this will help. It would have helped me...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值