我首先将脚本配置为即使HTTP请求结束后也可以运行

 ignore_user_abort(true);

然后冲洗掉一些文字。
 echo "Thats all folks!";
 flush();

现在如何让浏览器认为HTTP请求已结束?因此我可以继续自己的工作,而浏览器不会显示“页面加载”。
 header(??) // something like this?

最佳答案

这是操作方法。您告诉浏览器读入输出的前N个字符,然后关闭连接,而脚本将一直运行直到完成为止。

<?php
ob_end_clean();
header("Connection: close");
ignore_user_abort(true); // optional
ob_start();
echo ('Text the user will see');
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush();     // Will not work
flush();            // Unless both are called !

// At this point, the browser has closed connection to the web server

// Do processing here
echo('Text user will never see');
?>

10-08 09:17
查看更多