Home > Backend Development > PHP Tutorial > ob_start()求教解决思路

ob_start()求教解决思路

WBOY
Release: 2016-06-13 13:20:27
Original
805 people have browsed it

ob_start()求教
ob_start(); //-----------------------------1

//for($s=0;$s
//ob_end_clean(); //----------------------------------2

for($var=0;$var echo $var;
print str_repeat("", 4096); 
ob_flush();//--------------------------3
flush(); //--------------------------4
  sleep(1); //--------------------------5
}
?>
一个测试缓冲区的例子,问题来了,当使用ob_start()函数时候,【3】的作用是释放缓冲区的内容,【4】将不再缓冲区的内容发送到页面,【5】使得每秒发送一次,但是为什么还会等10秒后一次将内容全发送过去.

查了很多文章,很多都说使用【2】处的方法,注释掉【1】【3】,但是这样就关闭了缓冲区,

网上关于Php的说法有称内部缓冲区的,也有叫缓冲区的,不知道是不是一个东西。
还有Php.ini文件中的 output_buffering他的缓冲区是不是就是ob_start()开启的缓冲区?

------解决方案--------------------
ob_flush不是很好用,请参考官方文档。
http://il.php.net/manual/en/function.ob-flush.php

some problems with ob_flush() and flush() could be resolved by defining content type header :
header( 'Content-type: text/html; charset=utf-8' );

so working code looks like this:
header( 'Content-type: text/html; charset=utf-8' );
echo 'Begin ...
';
for( $i = 0 ; $i {
echo $i . '
';
flush();
ob_flush();
sleep(1);
}
echo 'End ...
';
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template