Tracing a PHP "out of memory" error


I’m building an application with the Yii framework and am trying to determine the cause of an out of memory error. Is it possible to get a stack trace? I’ve tried doing something like…

function handleShutdown() {
    $error = error_get_last();
    $info = "[SHUTDOWN] file:".$error['file']." | ln:".$error['line']." | msg:".$error['message'] .PHP_EOL;
    echo $info;

But the debug_print_backtrace() doesn’t show anything but

#0 handleShutdown()
[SHUTDOWN] file:C:\Users\bkuhl\htdocs\instaLabel\yii-1.1.12\base\CModule.php | ln:530 | msg:Allowed memory size of 67108864 bytes exhausted (tried to allocate 65488 bytes)

I’ve checked CModule.php and there’s no line number 530 in that file. It only goes to 518.


In my case, this was happening because I had infinite function recursion. When I added the xDebug extension to PHP it threw an accurate error due to the function call limit.

Answered By – Ben

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published