gpt4 book ai didi

PHP Flush/ob_flush 不工作

转载 作者:可可西里 更新时间:2023-10-31 22:52:40 27 4
gpt4 key购买 nike

我已经尝试了几次尝试让我的 flush 和 ob_flush 工作。我试过设置 ini 以允许缓冲,我试过使用我在网上找到的几个不同的函数来进行输出缓冲,但没有一个起作用。该脚本想要等到它完全完成,直到它回显输出。这是我目前的脚本

 ob_start();

//Login User
echo 'Logging in to user<br>';
ob_flush();
flush();
$ch = curl_init("http://www.mysite.com/login/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$user&pass=$pass");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies/$cookie");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies/$cookie");
$output = curl_exec($ch);
curl_close($ch);
ob_flush();
flush();

//Update Status
echo 'Updating Status<br>';
ob_flush();
flush();
$ch = curl_init("http://www.mysite.com/update/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "status=$status");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies/$cookie");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies/$cookie");
$output = curl_exec($ch);
curl_close($ch);
ob_flush();
flush();

我希望它回显它正在做什么,然后运行该函数,然后回显其他内容,然后执行另一个函数。我希望在浏览器上实时刷新和回显所有缓冲区。

最佳答案

这里的想法是禁用输出缓冲,而不是启用它。顾名思义,输出缓冲会将输出保存到内存中,并在脚本末尾或在明确要求时显示。

也就是说,您不必为每个输出显式刷新。在显示任何输出之前使用以下命令,这样您就不必在每次回显时都刷新:

ob_implicit_flush(true);
ob_end_flush();

例如:

ob_implicit_flush(true);
ob_end_flush();

for ($i=0; $i<5; $i++) {
echo $i.'<br>';
sleep(1);
}

将输出 0 到 4,每个每秒显示一次。

关于PHP Flush/ob_flush 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4481235/

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