在ajax更新期间离开网页

时间:2014-05-26 03:02:46

标签: javascript php ajax angularjs asynchronous

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

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

我使用angularjs对LAMP堆栈进行异步调用。

1 个答案:

答案 0 :(得分:3)

假设:

  • 服务器收到该请求
  • 服务器可以在没有错误的情况下处理它
  • 该请求处理程序中有一个数据库更新逻辑

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

正如@ AD7six指出并根据this php manual reference

<强>为什么:

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.


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

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

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