是否可以断开http客户端与PHP的连接?

时间:2010-08-22 17:14:39

标签: php apache http

  1. 在PHP中是否可以(并且是安全的)关闭http连接而不返回任何http状态代码?我的服务器是apache。
  2. 是否会将其记录到访问日志或错误日志中?

4 个答案:

答案 0 :(得分:6)

我使用以下代码:

/**
 * Make the script run in the background
 * return a message to the browser
 * @param unknown_type $response
 */
function freeUserBrowser($response)
{
        // let's free the user, but continue running the
        // script in the background
        ignore_user_abort(true);
        header("Connection: close");
        header("Content-Length: " . mb_strlen($response));
        echo $response;
        flush();

}

答案 1 :(得分:3)

我不认为这是可能的:最终是Apache关闭连接,如果PHP没有发出连接,则返回状态代码。

前段时间我们有一个问题是关于是否可以在PHP中强制切断http连接。 IIRC的共识是,除了击落负责当前请求的Web服务器线程外,这是不可能的。现在正在寻找问题... 更新:现在找不到,抱歉。

答案 2 :(得分:1)

我不这么认为,没有杀死阿帕奇工人本身,这肯定不是一个好主意。

如果将PHP用作Apache模块,则可能。可能有一些Apache内部函数可用于您可以使用的模块,但我不知道Apache内部的足够信息。

答案 3 :(得分:1)

简而言之,Apache会发号称,出于安全原因,您无法从外部更改Apache行为。

相关问题