在ajax更新期间离开网页

Leaving a webpage during an ajax update

本文关键字:离开 网页 ajax 更新      更新时间:2023-09-26

当用户向服务器发送异步请求以更新其数据库时,可能需要几分钟,但在更新完成之前就离开了网页,会发生什么?

服务器将继续记录更新到数据库还是停止?

我正在使用angularjs来异步调用LAMP堆栈

假设:

  • 服务器收到请求
  • 服务器可以无错误地处理
  • 请求处理程序中有一个数据库更新逻辑

no,服务器将不将更新记录到数据库中。

正如@AD7six指出的,根据这个php手册参考:

原因:

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.

选项:

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.

如何:

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.


也有一个TIMEOUT中止:

原因:

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.

选项:

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.


这是基本的客户机-服务器通信流:

客户端(网页、浏览器等)向服务器
发送请求 (sync/async)服务器客户端发送响应

服务器可以像客户端一样处理连接超时和中止。