php – register_shutdown_function做什么?
<?php echo "Here is my little script"; function endScript(){ echo "My little Script has finished"; } register_shutdown_function('endScript'); ?> 基本上,脚本运行和完成后会发生什么,因为我们添加了这一行register_shutdown_function(‘endScript’);它会调用函数endScript,最后输出我的小脚本已经完成了. 这里有一点点从documentation:
*更新 当您经常在php中使用名为exit()的函数时,很有用. 例如: <?php function endScript(){ echo "My little Script has finished"; } register_shutdown_function('endScript'); $result = some_intricate_function() if($result == 0){ exit(); } $result = some_other_intricate_function() if($result == 0){ exit(); } /* and this keeps reoccurring */ ?> 现在注意到,即使您多次呼叫退出,您也不必在退出之前调用endScript函数.你在开始注册了,现在你知道如果你退出或你的脚本完成,那么你的功能被调用. 现在我的关机功能当然是没用的;但是如果您需要清理的东西(例如,关闭打开的文件句柄,保存一些持久数据等),它将变得有用 (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |