您好,欢迎访问一九零五行业门户网

php利用缓冲实现动态输出(flush,ob_flush)

php利用缓冲实现动态输出通过 flush,ob_flush实现
print str_repeat( , 4096);//php.ini output_buffering默认是4069字符或者更大,即输出内容必须达到4069字符服务器才会flush刷新输出缓冲for ($i=10; $i>0; $i--){ echo $i; ob_flush(); flush(); sleep(1);}//ob_flush()和flush()的区别。前者是把数据从php的缓冲中释放出来,后者是把不在缓冲中的或者说是被释放出来的数据发送到浏览器。所以当缓冲存在的时候,我们必须ob_flush()和flush()同时使用。
//附上一段非常有趣的代码,作者为puttyshell。在一个脚本周期里,每次输出,都会把前一次的输出覆盖掉。header('content-type: multipart/x-mixed-replace;boundary=endofsection'); print \n--endofsection\n; $pmt = array(-, \\, |, / ); for( $i = 0; $i $i ++ ){ sleep(1); print content-type: text/plain\n\n; print part $i\t.$pmt[$i % 4]; print --endofsection\n; ob_flush(); flush(); } print content-type: text/plain\n\n; print the end\n; print --endofsection--\n;
其它类似信息

推荐信息