Hello all,

While working on one of our projects i stumbled on what i think is a 
problem in the Zend engine regarding the memory limit code. On some scripts 
the server reported memexhausts when the site had heavy traffic. I wrote a 
PHP extension that can return a script's memory usage at any time during 
execution, to find out what caused these errors. The memory usage extension 
uses two methods, the first being the total of all allocated persistent and 
regular memory blocks (REAL_SIZE), the second method is just a return of 
the variable AG(allocated_memory).

Now in one of the scripts i was monitoring i noticed a constant increase in 
memory usage (using the second method described earlier) of 10KB when 
constantly reloading in my browser. Using the second method the memory 
usage was constant.

After some investigation i discovered that that particular script leaked 10 
KB of memory on every request. I analyzed the memory limit code in Zend, 
and adapted sapi/apache/mod_php4.c to not only return 
AG(allocated_memory_peak) as an Apache variable, but also 
AG(allocated_memory) to check whether AG(allocated_memory) was zero after 
execution of each script.

This was not the case. When a script leaks memory (which really shouldn't 
happen, but it does), after its execution AG(allocated_memory) still 
contains the amount of memory that was not de-allocated. This is what seems 
to cause the trouble. Since AG(allocated_memory) is not always zero after 
execution of a script, and AG(allocated_memory_peak) is dependant on it, 
consecutive requests on a leaking script result in an ever increasing 
AG(allocated_memory) and thus an ever increasing AG(allocated_memory_peak), 
which at a certain moment results in AG(allocated_memory_peak) > 
AG(memory_limit). This is what caused the memory exhaust errors.

I noticed that AG(allocated_memory_peak) *is* reset after script execution 
in sapi/apache/mod_php4.c, but AG(allocated_memory) isn't. I should really 
be tracking down the reason for the script to leak 10 KB of memory, but i 
fixed this problem temporarily by adding a AG(allocated_memory) = 0 line to 
mod_php4.c in function send_parsed_php(), though i'm not sure if this is 
the right thing to do. For now it fixes the memory exhausts.

I am interested in hearing your views on this matter.

With regards,

Hans Rakers


-- 
Hans Rakers ([EMAIL PROTECTED])             Tel: +31 (0)23 5325689
System administrator/Developer          Fax: +31 (0)23 5314332
Parse - Postcode.NL - TeKoop.NL         http://www.parse.nl/
Haarlem, the Netherlands


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to