I came across a terrible error message, perhaps due to painstaking effort, PHP ran out of memory:
The allowed memory size #### bytes has been exhausted (tried to allocate #### bytes) in the .php file on line 123
Limit increase
If you know what you are doing and want to increase the limit, see memory_limit :
ini_set('memory_limit', '16M'); ini_set('memory_limit', -1); // no limit
Caution! You can solve only a symptom, not a problem!
Leak diagnosis:
The error message points to a line with a loop that I believe is leaking or unnecessarily accumulating memory. I typed the expression memory_get_usage() at the end of each iteration and can see that the number slowly grows until it reaches the limit:
foreach ($users as $user) { $task = new Task; $task->run($user); unset($task);
For the purposes of this question, suppose the worst spaghetti code imaginable is hiding in a global area somewhere in $user or Task .
What tools, PHP tricks, or voodoo debugging can help me find and fix the problem?
php memory-leaks
Mike B May 11 '09 at 19:04 2009-05-11 19:04
source share