Connecting Tech Pros Worldwide Forums | Help | Site Map

memory allocation problems in PHP and how to optimize?

lawrence
Guest
 
Posts: n/a
#1: Jul 17 '05
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.

Pedro
Guest
 
Posts: n/a
#2: Jul 17 '05

re: memory allocation problems in PHP and how to optimize?


lawrence wrote:[color=blue]
> PHP keeps throwing out-of-memory errors on me. By default PHP only
> allows a script 8 megs of memory.[/color]
[...]


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.
lawrence
Guest
 
Posts: n/a
#3: Jul 17 '05

re: memory allocation problems in PHP and how to optimize?


Pedro <hexkid@hotpop.com> wrote in message news:<bmi3q1$mv5s7$2@ID-203069.news.uni-berlin.de>...[color=blue]
> lawrence wrote:[color=green]
> > PHP keeps throwing out-of-memory errors on me. By default PHP only
> > allows a script 8 megs of memory.[/color]
> [...]
>
>
> check memory_get_usage()[/color]

Outstanding. I searched on Google and came up with nothing. Thanks
much, this will make debugging much easier.
Closed Thread