我正在手动运行一个 PHP 数据库维护脚本,大约需要 10-15 分钟才能完成。如果我的计算机在此期间失去网络连接,脚本是否总是在服务器上完全完成,还是在途中某处停止?
如果确实停止了,我可以在 PHP 或 apache 配置中做些什么来防止这种情况发生吗?
最佳答案
看看:http://php.net/manual/en/function.ignore-user-abort.php
When running PHP as a command line script, and the script's tty goes away without the script being terminated, then the script will die the next time it tries to write anything unless
ignore_user_abort
is set to TRUE.
您还可以通过 CronJob 启动脚本。如果此任务是重复性的,这可能是更好的解决方案。
但在这两种解决方案中,使用 set_time_limit()确保您的 max_execution_time
不会取消脚本的执行。
关于php - 如果客户端浏览器丢失或关闭连接,事件脚本请求是否完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42457116/