gpt4 book ai didi

php - 立即打印结果(php)

转载 作者:行者123 更新时间:2023-12-02 23:27:46 25 4
gpt4 key购买 nike

我有一个 PHP 脚本,它连接 10 个不同的服务器来获取数据。我希望它在第二个连接开始之前打印第一个连接的结果。

最佳答案

使用flush和/或 ob_flush ,你应该得到你想要的。

这是一个快速演示:

for ($i=0 ; $i<10 ; $i++) {
echo "$i<br />";
ob_flush();
flush();
sleep(1);
}

每秒,一个数字将被发送到浏览器,而不等待循环/脚本结束。
(没有flush和ob_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.


如果这对您不起作用,请查看手册两页上的注释,可以为您提供一些有关“为什么会失败”的提示

关于php - 立即打印结果(php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1363600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com