如何确保用户不能中断执行由“register_shutdown_function”调用的php代码? [英] How to make sure the user cannot interrupt execution of php code called by "register_shutdown_function"?

查看:332
本文介绍了如何确保用户不能中断执行由“register_shutdown_function”调用的php代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确保某些在php关闭函式中执行的程式码(通过register_shutdown_function注册)也会执行,如果使用者离开网页或关闭该网页的分页或整个浏览器,在执行关闭代码之前,但在页面显示后?



我只是想确保用户不会中断关机代码,一旦页面显示。 / p>

我指的是:



http://www.php.net/manual/function.register-shutdown-function.php#92959



你认为Filp.dalge在php.net这个注释中的代码是否正确?



必要的所有PHP版本(只感兴趣> = 5.0)?

解决方案

关闭函数将始终 >被执行(除非有一个致命的PHP错误),所以你不需要任何额外的代码。该注释中的代码是强制Web服务器刷新所有缓冲区,并在执行代码之前将生成的数据发送到浏览器。我不会使用它,如果你打算使用 register_shutdown_function()在别处(或者如果任何库你需要使用它),因为它改变了应用程序的状态 - 另一个关闭处理程序可能希望打开连接到浏览器,例如。


How can I make sure that some code, that is executed in a php shutdown function, that was registered via "register_shutdown_function" is also executed, if the user leaves the page or closes the tab or the whole browser of that page, before the shutdown code is executed, but after the page is displayed?

I just want to make sure the user cannot interrupt the shutdown code, once the page is displayed.

I refer to this:

http://www.php.net/manual/function.register-shutdown-function.php#92959

And do you think the code of Filip Dalge in this comment on php.net is the correct way?

Is it necessary for all php versions (only interested in >= 5.0) ? How (if so) does this behavior change in the different versions?

解决方案

The shutdown function will always be executed (unless there is a fatal PHP error), so you don't need any extra code. The code in that comment is to force the web server to flush all buffers and send the generated data to the browser before executing the code. I wouldn't use it if you plan to use register_shutdown_function() elsewhere (or if any library you need makes use of it), since it changes the state of the application - another shutdown handler might expect an open connection to the browser, for example.

这篇关于如何确保用户不能中断执行由“register_shutdown_function”调用的php代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆