作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我试过了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/
我是一名优秀的程序员,十分优秀!