如果用户退出浏览器或更改页面之前AJAX请求结束,会发生什么 [英] What happens if a user exits browser or change page before AJAX request is over

查看:132
本文介绍了如果用户退出浏览器或更改页面之前AJAX请求结束,会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话PHP脚本在AJAX做一些数据库维护。如果用户关闭网页,打回,或者点击一个链接时,将PHP脚本完全执行?有没有办法做到这一点?

I am calling a php script over ajax to do some database maintenance. If the user closes the page, hits back, or clicks a link, will the php script be fully executed? Is there a way to do it?

也许,如果PHP脚本称为 EXEC()法或类似的东西,这将反过来通过控制台这样调用脚本:

Maybe if the php script called the exec() method or something similar, which would in turn call a script via the console as such:

$ php /var/www/httpdocs/maintenance.php

推荐答案

只要用户代理(浏览器等)已经充分发送请求,服务器的所有需要​​,并会完成请求,并尝试发送回一个响应。

As long as the user agent (browser, etc.) has fully sent the request, the server has all it needs and will complete the request and try to send back a response.

其实,这样的ping命令的行为经常被用于心跳般的保持服务热情,或进行定期维护过程。

In fact, this sort of "pinging" behavior is often used for "heartbeat"-like processes that keep a service warm or perform periodic maintenance.

这篇关于如果用户退出浏览器或更改页面之前AJAX请求结束,会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆