在ajax更新期间离开网页

use*_*508 6 javascript php ajax asynchronous angularjs

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

服务器是否仍会将更新记录到数据库或停止?

我正在使用angularjs来对LAMP堆栈进行异步调用.

Fer*_*osa 3

假如说:

  • 服务器收到该请求
  • 服务器可以正确处理它
  • 该请求处理程序中有一个数据库更新逻辑

那么不行,服务器不会将更新记录到数据库中。

正如 @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.


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

客户(网页、浏览器......)向服务器发送请求(同步/异步), 服务器通过响应来响应客户

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

  • 这是一个过于简单化的答案,否则[这样的选项](http://www.php.net/manual/en/function.ignore-user-abort.php)将不存在。请参阅[连接处理](http://php.net/manual/en/features.connection-handling.php)。 (3认同)