PHP's Poor Memory Managment

Discussion in 'Linux VPS/Dedicated - General' started by guru_ck, Jun 1, 2007.

  1. guru_ck

    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.
     
  2. guru_ck

    guru_ck New Member

    Here are my resoruces after running the case above... ignore the httpd instances... I have a busy site right now. http://ck84.ws/top.txt
     
  3. guru_ck

    guru_ck New Member

    20 minutes later free memory is still at zero. My server is running fine however. I don't get it. PHP is killing something.
     
  4. khiltd

    khiltd New Member

    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?
     
  5. guru_ck

    guru_ck New Member

    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.
     
  6. ppc

    ppc Moderator

    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?
     
  7. khiltd

    khiltd New Member

    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.
     
  8. guru_ck

    guru_ck New Member

    http://ck84.ws/top.txt
     
  9. KH-Paul

    KH-Paul CTO Staff Member

    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
     

Share This Page