如何实现超载关机功能?
我正在使用 Kohana (v3) 框架,但我相信它与特定框架无关。
我所拥有的基本上是一个带有前端的应用程序,我想在其中使用 Kohana 的本机 Kohana::shutdown_handler()
,但我也有一部分 - RESTful API - 但我不这样做”不需要彩色的 html 编码的异常报告。我想要一份纯文本报告。
我认为它可能工作的方式是在 API 的控制器抽象类构造函数中注册另一个关闭函数,但后来我意识到 register_shutdown_function()
的工作方式与 set_exception_handler()
不同,而不是替换它会为关闭程序添加另一个功能。更糟糕的是 PHP 不允许“取消注册”关闭函数,这就是我的问题所在。
如果您想使用另一个关闭功能而不是已经注册的功能,该怎么办?
I am using Kohana (v3) framework but I believe it's not tied to a particular framework.
What I have is basically an app with a front-end, where I want to use Kohana's native Kohana::shutdown_handler()
, but I also have a part of the - RESTful API - where I don't want colourful and html-encoded exception reporting. I want a plain text reporting.
The way I thought it might work is to register another shutdown function in API's controller abstract class constructor, but then I realised register_shutdown_function()
works differently to set_exception_handler()
and instead of replacing it adds another function to the shutdown procedure. What's worse PHP doesn't allow "unregistering" shutdown functions and that's where my problem lies.
What to do, if you want to use another shutdown function instead of one already registered?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以简单地超载
by your custom view and set
You can simply overload
by your custom view and set
首先想到的是在任何其他
register_shutdown_function()
调用之前添加您的函数,并让它调用任何必要的关闭函数,然后调用 exit 或 die 立即结束脚本,而不调用其他关闭功能。为了确保您的调用是第一个,我会为其创建一个单独的文件并将其添加为 php.ini 的 auto_prepend_file。
称之为黑客……也许吧。有效吗?我99%确信应该如此。
The first thing that comes to mind would be to add your function before any other
register_shutdown_function()
calls and have it call any necessary shutdown functions and then call exit or die to immediately end the script without calling other shutdown functions.To ensure your call is first, I would make a separate file for it and add it as php.ini's auto_prepend_file.
Call it a hack...maybe. Does it work? I'm 99% sure it should.