PHP脚本可以欺骗浏览器认为HTTP请求结束了吗?

Rob*_*cks 6 php scripting webserver http httpwebrequest

我首先将我的脚本配置为在HTTP请求结束后运行

 ignore_user_abort(true);
Run Code Online (Sandbox Code Playgroud)

然后清除一些文字.

 echo "Thats all folks!";
 flush();
Run Code Online (Sandbox Code Playgroud)

现在我怎么欺骗浏览器认为HTTP请求结束了?所以我可以继续做自己的工作而不需要浏览器显示"页面加载".

 header(??) // something like this?
Run Code Online (Sandbox Code Playgroud)

Mil*_*kov 10

这是怎么做的.您告诉浏览器读取输出的前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');
?>
Run Code Online (Sandbox Code Playgroud)

  • 与手册页中的代码相同(对于字母)链接到Lukman的答案,该答案是两天前发布的. (3认同)