Home  >  Article  >  Backend Development  >  PHP使用缓存即时输出内容(output buffering)的方法_PHP

PHP使用缓存即时输出内容(output buffering)的方法_PHP

WBOY
WBOYOriginal
2016-05-30 08:47:20997browse

PHP使用缓存即时输出内容(output buffering)的方法。分享给大家供大家参考。具体如下:

$buffer = ini_get('output_buffering');
echo str_repeat(' ',$buffer+1); //防止浏览器缓存
ob_end_flush(); //关闭缓存
for( $i=1; $i<=10; $i++ ){
  echo '第 '.$i.' 次输出.'."
\n"; flush(); //刷新缓存(直接发送到浏览器) sleep(1); } echo '输出完毕!';

运行效果如下:

第 1 次输出.
第 2 次输出.
第 3 次输出.
第 4 次输出.
第 5 次输出.
第 6 次输出.
第 7 次输出.
第 8 次输出.
第 9 次输出.
第 10 次输出.
输出完毕!

希望本文所述对大家的php程序设计有所帮助。

Statement:
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