我拷贝代码的地址是:http://fr2.php.net/manual/zh/function.ob-flush.php#109314
我的代码如下,执行后不是逐行显示,而是等了很长时间后,一起出现出来:
header('Content-type:text/html; charset=utf-8');
if (ob_get_level() == 0) ob_start();
for ($i = 0; $i<10; $i++){
echo "<br> Line to show.";
echo str_pad(' ',4096)."\n";
ob_flush();
flush();
sleep(2);
}
echo "Done.";
ob_end_flush();
OS:Mac osx 10.9
webservice: nginx 1.4
php: 5.6
高洛峰2017-04-10 14:42:14
运行毫无问题.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show. Done.
PHPz2017-04-10 14:42:14
注意flush
和ob_flush
的区别:ob_flush
操作的是php
本身的buffer
flush
操作的是 apache
的 flush
,也就是说这个对 nginx
是无效果的
nginx下要如下设置试一下:
fastcgi_max_temp_file_size 0 #禁止磁盘缓冲
fastcgi_buffers 1 1k #把buffer设小