gpt4 book ai didi

php - 如何在 php 脚本仍在运行时显示结果

转载 作者:行者123 更新时间:2023-12-01 11:55:43 27 4
gpt4 key购买 nike

所以我试过了Show results while script is still executing

但由于某种原因它不起作用,所以这是我目前所拥有的:

ob_start();
include "../../common.php";

set_time_limit (0);

$start = (string) $_GET['start'];
$end = (string) $_GET['end'];

for($i = $start; strcmp($i, $end); $i = bcadd($i, 1)){

echo $i;
ob_flush();

}

ob_end_flush();

更新代码

*请注意,这段代码还不能工作!

set_time_limit(0);

$start = $_GET['start'];
$end = $_GET['end'];

for(;$start < $end;$start++){
$content = file_get_contents("[some internal page]");
echo $content;
usleep(10);
flush();
}

最佳答案

尝试添加对 flush() 的调用在调用 ob_flush() 之后。这仅在您的服务器配置为能够执行此操作时才有效,并且不能保证客户端会明智地处理它,但这是您最好的选择。

我在这里遇到的一个关键点是你有 zlib.output_compression配置你绝对不能这样做,句号。 zlib 输出压缩过程在您的任何代码执行之前启动,并且无法在运行时通过脚本使用 ini_set() 等进行控制。

关于php - 如何在 php 脚本仍在运行时显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7570426/

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