代码之家  ›  专栏  ›  技术社区  ›  mmonem

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

  •  2
  • mmonem  · 技术社区  · 14 年前
    1. 在PHP中,关闭http连接而不返回任何http状态码是可能的(而且是安全的)吗?我的服务器是apache。
    2. 这会记录到访问日志还是错误日志?
    4 回复  |  直到 14 年前
        1
  •  3
  •   Pekka    14 年前

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

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

        2
  •  6
  •   Nir O.    13 年前

    我使用以下代码:

    /**
     * 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();
    
    }
    
        3
  •  1
  •   Artefacto    14 年前

    如果使用PHP作为Apache模块,这是可能的。可能有一些Apache内部函数可供模块使用,但我对Apache内部的了解还不够。

        4
  •  1
  •   Hydrino    14 年前