加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

立即打印结果(php)

发布时间:2020-12-13 16:34:46 所属栏目:PHP教程 来源:网络整理
导读:我有一个 PHP脚本连接10个不同的服务器来获取数据.我想要在第二个开始之前打印第一个连接的结果. 使用 flush 和/或 ob_flush ,你应该得到你想要的. 这是一个快速演示: for ($i=0 ; $i10 ; $i++) { echo "$ibr /"; ob_flush(); flush(); sleep(1);} 每秒钟,
我有一个 PHP脚本连接10个不同的服务器来获取数据.我想要在第二个开始之前打印第一个连接的结果.
使用 flush和/或 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.

如果这不适合您,请查看手册两页上的评论,可以给出几点“为什么会失败”的指针

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读