即使用户关闭了浏览器,PHP脚本也可以继续运行吗? [英] Can PHP scripts continue to run even if the user closed the browser?
问题描述
例如,有一个非常简单的PHP脚本可以更新数据库中的某些表,但是此过程需要很长时间(可能需要10分钟).因此,即使用户关闭了浏览器,我也希望该脚本继续处理,因为有时用户不等待,而是关闭浏览器或转到另一个网页.
For example, there is a very simple PHP script which updates some tables on database, but this process takes a long time (maybe 10 minutes). Therefore, I want this script to continue processing even if the user closed the browser, because sometimes users do not wait and they close the browser or go to another webpage.
推荐答案
To answer your question directly, see ignore_user_abort
更广泛地说,您可能在这里遇到架构问题.
More broadly, you probably have an architecture problem here.
如果许多用户可以启动这些工作,那么您将希望Web应用程序将作业添加到某种队列中,并具有一定数量的后台进程来处理所有工作.
If many users can initiate this stuff, you'll want the web application to add jobs to some kind of queue, and have a set number of background processes that chew through all the work.
这篇关于即使用户关闭了浏览器,PHP脚本也可以继续运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!