Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaving a webpage during an ajax update [duplicate]

What happens when a user sends an asynchronous request to a server to update its database that may take a couple minutes, but then leaves the webpage before the update is done?

Will the server still record the update to the database or stop?

I'm using angularjs to make async calls to a LAMP stack.

like image 200
user1424508 Avatar asked May 26 '14 03:05

user1424508


1 Answers

Assuming that:

  • the server received that request
  • the server can process it without erros
  • there is a database update logic in that request handler

Then no, the server will not record the update to the database.

As @AD7six pointed out and according to this php manual reference:

Why:

The default behaviour is however for your script to be aborted when the remote client disconnects.

If you do not tell PHP to ignore a user abort and the user aborts, your script will terminate.

Options:

You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output.

How:

This behaviour can be set via the ignore_user_abort php.ini directive as well as through the corresponding php_value ignore_user_abort Apache httpd.conf directive or with the ignore_user_abort() function.


There is a TIMEOUT abort as well:

Why:

Your script can also be terminated by the built-in script timer. The default timeout is 30 seconds.

If you do not tell PHP to ignore a user abort and the user aborts, your script will terminate.

Options:

It can be changed using the max_execution_time php.ini directive or the corresponding php_value max_execution_time Apache httpd.conf directive as well as with the set_time_limit() function.


This is the basic client-server communication flow:

The client (the webpage, browser..) send a request (sync/async) to a server and
the server responds with a reponse to the client.

The server can handle connection timeouts and abort as well as the client.

like image 94
Fernando Carvalhosa Avatar answered Nov 16 '22 05:11

Fernando Carvalhosa