对于运行时间较长的PHP程序来说可能都需要即时输出内容来查看运行情况。
header(“Content-type:text/html;charset=utf-8″);
#设置执行时间不限时
set_time_limit(0);
#清除并关闭缓冲,输出到浏览器之前使用这个函数。
ob_end_clean();
#控制隐式缓冲泻出,默认off,打开时,对每个 print/echo 或者输出命令的结果都发送到浏览器。
ob_implicit_flush(1);
ob_end_clean();
ob_implicit_flush(1);
while(1){
//部分浏览器需要内容达到一定长度了才输出
echo str_repeat("<div></div>", 200).'hello world<br />';
sleep(1);
//ob_end_flush();
//ob_flush();
//flush();
}
方法二
//实时显示输出
ob_end_flush();//关闭缓存
//echo str_repeat(" ",256); //ie下 需要先发送256个字节
set_time_limit(0);
for($i=0;$i<10;$i++){
echo "Now Index is :". $i."<br>";
flush();
sleep(1);
}