views:

94

answers:

3

Situation: a user clicks on a link, the server gets the request and starts processing it. In the meanwhile, the user clicks on another link, the server gets the new request while processing the 1st one. What happens? On the client side we only see the webpage from the 2nd request, but is the process from the 1st request killed on the server when receiving the 2nd one? And is it managed by the server or the language (Apache or PHP)?

+5  A: 

Depends. If the browser does not drop the connection to server, it'll have absolutely no idea that the client has navigated elsewhere. If it does drop the connection, it's up to the Web server to choose to detect it and abort the processing thread or not.

Either case, this is the nature of statelessness of HTTP. You shouldn't rely on anything in this regard.

Mehrdad Afshari
+1  A: 

Both requests get served (if the browser did send the second one).

You would only see the second page, but if you'll look into access_log you'll surely notice two requests.

That's how HTTP works.

alamar
A: 

You can use ignore_user_abort() to tell a script to continue (or not) after the connection has been terminated.

Greg