Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > PHP Memory Leak
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 31st October 18:06
contact.saschabraun
External User
 
Posts: 1
Default PHP Memory Leak



Hi Everybody,

I have a couple of foreach loops which are ending in a for loop,
which causes the apache to consume the complete memory of the
server system the php engine is running on.

The nesting level is at round about three and looking like that:

$num_new = 4;
if (is_array($array)) {
foreach ($array as $key => value) {
if ($value['element'] == 'test1') {
foreach ($value['data'] as $skey => $svalue) {
echo $svalue;
}
} elseif ($value['element'] == 'test2') {
foreach ($value['data'] as $skey => $svalue) {
echo $svalue;
}
}
if ($num_new > 0) {

// this part causes the memory leak

for ($i = 0; $i < $num_new; $i++) {
echo "sgasdgga";
}
}
}
}

I dont know if the above code is causing the memory leak the source
is a little more complex, if nessessary I will provide some more code,

Thank you!

I hope for a solution
  Reply With Quote


 


2 31st October 18:06
dmagick
External User
 
Posts: 1
Default PHP Memory Leak



If you don't know how are we supposed to know?

Add

memory_get_usage() calls all over the place and see what's going on.

eg:

error_log(__LINE__ . "\t" . memory_get_usage() . "\n", 3,
'/path/to/log.file');

at various spots and go from there.

--
Postgresql & php tutorials
http://www.designmagick.com/
  Reply With Quote
3 31st October 23:58
lists
External User
 
Posts: 1
Default PHP Memory Leak


I would do a in_array here..

if (in_array($value['element'], array('test1', 'test2') ) ) {
foreach ($value['data'] as $skey => $svalue) {
echo $svalue;
} }

where are you lowering this number? From what I can tell, it is always
going to be 4

you have a $i - 0 (a minus sign) not equals


How about that?

--
Jim Lucas


"Perseverance is not a long race;
it is many short races one after the other"

Walter Elliot

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
  Reply With Quote
Reply


Thread Tools
Display Modes




666