PHP:由于“致命”错误而突然终止请求的影响

发布于 2024-10-28 10:20:22 字数 299 浏览 5 评论 0原文

我遇到了一个奇怪的情况。

我的应用程序将大量跟踪日志记录到文件中。 (我不知道具体如何,我使用我的框架记录器。不过可以检查一下)

问题是,当应用程序因致命错误(仅致命)而终止时[示例 - “致命错误:在非对象上调用成员函数 someFunction()"] ,我最终没有日志,甚至在脚本执行期间应该更早记录的日志也是如此。

(是的,我尝试刷新日志,这也没有帮助。看起来应用程序因致命错误而终止,以某种方式取消了对应用程序早期点完成的文件的写入。

有什么想法吗?

谢谢你

I'm experiencing a strange situation.

My application logs lot of trace logs to a file. (I don't know exactly how, I use my frameworks logger. Can check this though)

Problems is, when an application is terminated by a fatal error (only fatal) [example - "Fatal error: Call to a member function someFunction() on a non-object"] , I end up with no logs, even logs that should have been recorded much earlier during the execution of my script.

(Yes, I tried to flush logs, this doesn't help either. It looks like the termination of the application by a fatal error, somehow cancels writing to files done at earlier points of the application.

Any ideas what goes on here?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

︶ ̄淡然 2024-11-04 10:20:22

致命错误是...好吧...致命:它会停止脚本的执行,而脚本不会执行任何应该执行的操作。

就您而言,我认为您的日志记录框架会记录到内存中 - 并且该内存中的日志仅在请求处理完成后才会写入文件。

一些日志机制这样做是为了避免在生成响应期间的不同点多次写入文件(这意味着保持文件锁定,以避免并发问题;或打开-关闭-重新打开-重新关闭-... it)

当您收到致命错误时,不会调用应在响应生成结束时完成的正常操作 - 因此,内存中的日志不会写入文件。

现在,唯一确定的方法是查看框架的日志记录机制;-)

A Fatal Error is... well... Fatal : it stops the execution of the script, which will not do anything that should have been done.

In your case, I suppose your logging framework logs into memory -- and that this in-memory log is only written to the file when the processing of the request is done.

Some logging mecanisms do that, to avoid writing to a file several times, at different points during the generation of the response (which means keeping the file locked, to avoid concurrency problems ; or opening-closing-reopening-reclosing-... it)

As you get a Fatal Error, the normal operation that should be done at the end of the response's generation is not called -- and, so, the in-memory log is not written to the file.

Now, the only way to know for sure would be to take a look at the logging mecanisms of your Framework ;-)

蓝色星空 2024-11-04 10:20:22

显然,帕斯卡提到的致命错误的致命性并不是100%致命的。

即使出现致命错误,以下内容也允许我保留日志:

function correctShutdown()
{
   logger->flush();
}

register_shutdown_function('correctShutdown');

Apparently, the fatality of the fatal error that Pascal mentioned, is not 100% fatal.

The below allowed me to have my logs even on fatal errors:

function correctShutdown()
{
   logger->flush();
}

register_shutdown_function('correctShutdown');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文