Detect when running time is near max_execution_time

假如想象 提交于 2019-12-20 05:18:38

问题


I want my script to detect when it's near the maximum execution time, so it can stop and update the database.

I know phpMyAdmin does something like this when importing large files, I just don't know how.

register_shutdown_function() won't work as far as I can tell. It will work when doing a simple echo "test";, but not when doing any database operation. Any ideas?


回答1:


register_shutdown_function() can work... all instantiated object sare still present, but you need to make sure they're available in the scope of your shutdown callback function, which means you need to register the shutdown function after setting up your db connection, and pass the db connection as an argument to the callback function. The shutdown function is also called when the script terminates normally, or via a connection abort, so you need to ensure that you're not duplicating work that has already been done



来源:https://stackoverflow.com/questions/9310375/detect-when-running-time-is-near-max-execution-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!