By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,855 Members | 1,988 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,855 IT Pros & Developers. It's quick & easy.

memory allocation problems in PHP and how to optimize?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.