Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens in the server when a page load is cancelled in the browser?

In a fictitious web application ...

  1. The user clicks a link
  2. The server starts to prepare the response, but it takes several seconds
  3. The user cancels the page load

What happens to the request? Does the server continue to prepare the response? Does the response arrive to the browser?

like image 766
hectorsq Avatar asked Oct 29 '08 04:10

hectorsq


2 Answers

The server will continue to prepare the response. When it tries to send the response to the client, it'll fail. When this actually happens will probably depend on the actual application server implementation, whether the response is buffered etc.

In Java EE app servers (Tomcat and WebLogic, probably others as well), you'll get the following exception:

java.net.SocketException: Connection reset by peer: socket write error
like image 83
Jack Leow Avatar answered Sep 25 '22 00:09

Jack Leow


PHP understands three states of connection: NORMAL, ABORTED and TIMEOUT. You can change PHP's policy on ABORTED connections (by default, the script is terminated) with the ignore_user_abort() function. From the notes section:

"PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client."

Note that if your server's output is buffered, a send may not occur immediately.

See PHP's page on connection handling for more details.

like image 41
Artelius Avatar answered Sep 22 '22 00:09

Artelius