PHP's Poor Memory Managment

guru_ck

New Member
Hi All,

Here are the steps to reproduce my issue:
1) Visit www.ck84.ws/phpsysinfo
2) Press F5 around 50 times
3) Note the "Free" memory
4) Wait a few minutes and refresh once

The free memory is at 0KB. I've waited about 5 minutes now and it stil remains there. Eventually it will probably release some of that memory that is no longer in use but it never gets back to the point it was prior to pressing F5 50 times.
 
20 minutes later free memory is still at zero. My server is running fine however. I don't get it. PHP is killing something.
 
What exactly is it that's giving you the impression that PHP, out of all the hundreds of processes that are probably running concurrently, is consuming all of this memory?
 
Well if I do 5 dozen refreshes on my main HTML page then everything is OK. However if I do it when running a PHP script (such as phpsysinfo) then everything goes to hell and it never releases my memory until I restart httpd.
 
guru_ck: I do see what your talking about. If you quickly click F5 to reload the memory seems to be going done due to it. Maybe its caching but I'm not exactly sure.

KH: care to share some light on this?
 
Well if I do 5 dozen refreshes on my main HTML page then everything is OK. However if I do it when running a PHP script (such as phpsysinfo) then everything goes to hell and it never releases my memory until I restart httpd.

How about looking at top and getting some more accurate information before jumping to conclusions? You don't have very much memory to begin with and it's not at all uncommon for 256MB to disappear on a regular basis if you're using any of the popular hosting control panels.
 
I wouldn't call this poor memory management in PHP but rather poor script with memory leaks in it - basically what you're seeing means simple thing - script allocates resources and don't care about freeing them up. Solutions are:
- Don't use such badly written script(s);
- Check and fix script code to free up resources then they become unused;
- Set MaxRequestsPerChild option in Apache config to some very low value to force Apache to kill child process once it will serve pre-defined number of requests. Please note that setting MaxRequestsPerChild to very low value will increase your CPU usage;
- Restart Apache after each script execution ;)

Regards,
Paul
 
Top