Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracing a PHP "out of memory" error

Tags:

php

debugging

yii

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() {
    debug_print_backtrace();
    $error = error_get_last();
    $info = "[SHUTDOWN] file:".$error['file']." | ln:".$error['line']." | msg:".$error['message'] .PHP_EOL;
    echo $info;
}
register_shutdown_function('handleShutdown');

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.

like image 310
Webnet Avatar asked Nov 06 '12 14:11

Webnet


2 Answers

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.

like image 151
Webnet Avatar answered Nov 02 '22 11:11

Webnet


Profile your app with xdebug. It should tell you which function is called how often and how much memory it eats.

like image 27
Gung Foo Avatar answered Nov 02 '22 11:11

Gung Foo