开发者

Is it possible to disconnect an http client from PHP?

  1. In PHP is it possible (and is it safe) to close the http connection without r开发者_如何学运维eturning any http status code? My server is apache.
  2. Will this be logged to the access log or error log?


I use the following code:

/**
 * 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();

}


I don't think this is possible: Ultimately it's Apache who closes the connection, and returns a status code if PHP doesn't emit one.

We had a question some time ago about whether http connections can be forcibly cut off from within PHP. IIRC, the consensus was that except for shooting down the web server thread responsible for the current request, this was not possible. Looking for the question now... Update: Can't find it right now, sorry.


I don't think so, short of killing the apache worker itself, which would certainly not be a good idea.

It may be possible if using PHP as an Apache module. There may be some Apache internal function available to modules that you could use for this, but I don't know enough of Apache internals to tell for sure.


In nutshell Apache calling the shots, and you cannot change Apache behaviour from outside, for security reasons.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜