使用
原文链接:https://www.f2er.com/php/132428.htmlflush
和/或
ob_flush
,你应该得到你想要的.
这是一个快速演示:
for ($i=0 ; $i<10 ; $i++) { echo "$i<br />"; ob_flush(); flush(); sleep(1); }
每秒钟,一个数字将被发送到浏览器,而不用等待循环/脚本结束.
(没有flush和ob_flush,它等待直到脚本结束发送输出)
说明你为什么需要这两个,从手册中的flush页引用:
Flushes the write buffers of PHP and
whatever backend PHP is using (CGI,a
web server,etc). This attempts to
push current output all the way to the
browser with a few caveats.flush() may not be able to override
the buffering scheme of your web
server and it has no effect on any
client-side buffering in the browser.
It also doesn’t affect PHP’s userspace
output buffering mechanism. This means
you will have to call both ob_flush()
and flush() to flush the ob output
buffers if you are using those.
如果这不适合您,请查看手册两页上的评论,可以给出几点“为什么会失败”的指针