468,107 Members | 1,253 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

memory allocation problems in PHP and how to optimize?

PHP keeps throwing out-of-memory errors on me. By default PHP only
allows a script 8 megs of memory. I want to know why my script has
gotten so out-of-control when it comes to memory use. I'm assuming
there must be some array somewhere that is bloating up with
information, perhaps information that I assumed was being detroyed. It
could be a rather small mistake, causing a big problem. But how does
one debug memory allocation in PHP? There is no way, that I'm aware
of, to see the memory usage of all variables at all times.

Even if I had the patience to hit every variable in all my code with
var_dump(), just to get a rough estimate of their sizes, that still
wouldn't help, because the moment the var goes over 8 megs, it
crashes, before var_dump would have the time to print the info to me.
Jul 17 '05 #1
2 12142
lawrence wrote:
PHP keeps throwing out-of-memory errors on me. By default PHP only
allows a script 8 megs of memory.

[...]
check memory_get_usage()

maybe put it in a function:

<?php
function debug_memory($reason) {
echo $reason, ': ', memory_get_usage();
}
?>

and then call it before/after selected instructions

<?php
$a = $b; debug_memory('array copy');

$b = NULL; debug_memory('NULLified array');
?>
HTH

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #2
Pedro <he****@hotpop.com> wrote in message news:<bm************@ID-203069.news.uni-berlin.de>...
lawrence wrote:
PHP keeps throwing out-of-memory errors on me. By default PHP only
allows a script 8 megs of memory.

[...]
check memory_get_usage()


Outstanding. I searched on Google and came up with nothing. Thanks
much, this will make debugging much easier.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by DLPnet | last post: by
74 posts views Thread by ballpointpenthief | last post: by
7 posts views Thread by Ravi | last post: by
34 posts views Thread by jacob navia | last post: by
3 posts views Thread by rupert.thurner | last post: by
8 posts views Thread by rahul | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.