Call a function before the page is timeout in PHP

落爺英雄遲暮 提交于 2020-01-04 06:25:50

问题


I have a PHP script that will run for a long time. I have set the execution time limit to 5 minutes by using set_time_limit() function. I would like to ask whether I can set the script to call a function when timeout limit is reached? like the page unload script in JavaScript or viewDidUnload function in NSViewController, in iPhone SDK ?


回答1:


You can use register_shutdown_function() to register a callback, that is called, when the execution finishes. You should also have a look at connection handling.




回答2:


You can do it by using register_shutdown_function() But this isn't good practice, remeber that you will catch also fatal error, parse errors etc.



来源:https://stackoverflow.com/questions/6759446/call-a-function-before-the-page-is-timeout-in-php

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