如何从致命错误“已用完允许的内存大小"中恢复

2021-12-26 00:00:00 error-handling php fatal-error

您是否知道从 PHP 致命错误中恢复的任何解决方案:允许的内存大小...耗尽"

Do you know any solution to recover from the PHP fatal error : "Allowed memory size ... exhausted"

我有一个关闭函数,当出现致命错误时会调用该函数.此函数从中创建一个 ErrorException,并记录它.

I have a shutdown function that is called when a fatal error appear. This function create an ErrorException from it, and logs it.

问题是:当没有更多可用内存时,它无法记录错误(我使用 Zend Framework 通过 FirePHP 登录 Firebug).

The problem is : when there is no more memory available, it can't log the error (I log in Firebug, via FirePHP, with Zend Framework).

所以我所说的如何从中恢复"是指如何执行基本的错误日志,并让 Zend Framework 发送标头,以便记录错误(在我的 Firebug 中)case) 和其他错误一样吗?

So what i mean by "how to recover from it", is how to perform basic error log, and let Zend Framework send the Headers, so that the error is logged (in Firebug in my case) as any other error ?

谢谢

推荐答案

此错误是一个致命错误 - 这意味着您无法从中恢复.如果 PHP 已达到其内存限制,它将无法分配更多内存来创建您的异常以及继续执行所需的任何其他内存.

This error is a fatal error - that means you cannot recover from it. If PHP has hit it's memory limit, it won't be able to allocate any more memory to create your exception and any other memory it needs to carry on its execution.

还有另一种类型的错误——可捕获的致命错误",顾名思义,可以在 try/catch 中捕获,但不幸的是内存大小分配不是其中之一.

There is another type of error - "catchable fatal error" which as the name suggests, can be caught in a try/catch, but unfortunately the memory size allocation is not one of them.

相关文章