PHP关闭HTTP连接然后继续处理?

PHP关闭HTTP连接然后继续处理?,php,http,Php,Http,为什么此函数的最后一行需要执行此操作?我不明白这里发生了什么。但它确实有效 function close_connection() { // if we're using sessions this stops them from hanging on other requests session_write_close(); // get the content length from the buffer (the whole point of the buffer)

为什么此函数的最后一行需要执行此操作?我不明白这里发生了什么。但它确实有效

function close_connection() {
    // if we're using sessions this stops them from hanging on other requests
    session_write_close();
    // get the content length from the buffer (the whole point of the buffer)
    header('Content-Length: 0');
    // close the connection
    header('Connection: close');
    // flush the buffers to the screen
    flush();

    // connection closing doesn't work without this. I don't know why
    echo ' ';
}

只要第一个字节输出到浏览器,就会发送头。

您也可以尝试使用
ob_end_flush()

我在实际使用之前尝试过使用
ob\u end\u flush()
。它什么也没做,所以我把它拿走了。可能是因为我的缓冲区完全空了?您可以使用:
$obsize=ob_get_length()
然后在标题内容长度中使用该输出大小:
标题(“内容长度:$obsize”)
我可以在不发送任何内容的情况下刷新缓冲区吗?可以,通过使用
ob_clean()
ob_get_clean()
如果服务器压缩输出,则需要使用标题禁用它(“内容编码:无\r\n”);