我很早就关闭了与客户端的连接:
static public function early_close( $output )
{
ignore_user_abort(true);
echo $output;
// Disable gzip compression in apache, as it can result in this request being buffered until it is complete,
// regardless of other settings.
if (function_exists('apache_setenv')) {
apache_setenv('no-gzip', 1);
}
// get the size of the output
$size = ob_get_length();
// send headers to tell the browser to close the connection
header("Content-Length: $size");
header('Connection: close');
header("Content-Encoding: none"); // To disable Apache compressing anything
// IF PHP-FM
// fastcgi_finish_request();
// flush all output
if( ob_get_level() > 0 )
{
ob_end_flush();
ob_get_level()? ob_flush():null;
flush();
}
// if you're using sessions, this prevents subsequent requests
// from hanging while the background process executes
if( session_id() )
{
session_write_close();
}
}
工作正常,但在此事件之后,如果某些脚本输出任何内容(通过回显或添加新标头),则脚本将从该点停止执行。
我试图在提前关闭后开始输出缓冲,然后将其丢弃,但它不起作用:
Server::early_close();
ob_start();
heavy_work();
ob_clean();
有任何想法吗?
使用 php 5.3.x