Leaving a webpage during ajax update

What happens when a user sends an asynchronous request to the server to update their database, which may take a couple of minutes, but then leaves the web page before the update is complete?

Will the server write the update to the database or stop?

I use angularjs to create asynchronous calls to the LAMP stack.

+6
source share
1 answer

Assuming that:

  • the server received this request
  • the server can handle it without erros
  • this query handler has the logic for updating the database

Then, no server will write the update to the database.

As pointed out by @ AD7six and according to this php help information :

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.


Cancel TIMEOUT :

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 main client-server communication flow:

the client (web page, browser ..) sends a request (synchronization / asynchronous) to the server and
server responds to the client .

The server can handle timeouts and interruptions of the connection, as well as the client.

+3
source

Source: https://habr.com/ru/post/969843/


All Articles