Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    171
    Thanks
    3
    Thanked 10 Times in 9 Posts

    PHP Memory Leaks issues

    I've got a site that has been running fine for almost 5 years. On Saturday, the site crashed. Called support to find that the drive on the dedicated server went south. They replaced the drive, but upgraded the OS to latest CentOS 5.x (closest match to what we had). I copied the code files and restored the database (thank god for backups!) and turned the site on.

    All was fine... for a while. Suddenly the site started slowing. Up and down, up and down. Very odd because same machine (all we replaced was drive and upgraded OS) had no problems for over 4 years. Called support to find that apache was running out of memory. They said it was likely a memory leak in our code. OK, fine, but then why has it not been an issue for 4 years? Of course, they don't know, they can't examine our code (liability). The support guy reduced the max number of apache connections to 2000 (from 4000), but it is just going to prolong the problem, I'd like to try to resolve it.

    So I started investigating. Some of the things I've come up with:

    1. The current OS is installed with PHP 5.3.3. I installed the previous system in Jan 2009, before 5.3 was released. I am "guessing" it was on 5.2, but not certain. I went through change log and migration documentation and couldn't find anything. I don't do anything really "cutting edge" so I'm wondering if this is a non-issue.

    2. One of the things we do is use an .htaccess file to run a script to make sure someone is logged in before streaming them an audio file. Seems benign, but I notice when a new audio goes up, we see more of the problem.

    3. I uploaded some new files and noticed they were owned by <user>:psacln. All the files I copied over (command line) were owned by root:root (what I was logged in as). I changed the permssions (recursively) on the web root (/var/www/httpdocs) to <user>:psacln and the site stopped working (unauthorized access). So I changed the folder only (not recursive) to <user>:psaserv and it seems to be fine (all files/folders under that root are now owned by <user>:psacln as if I had uploaded them by FTP).

    So, any ideas if I am moving in the right direction? So far, so good, but it's only been a couple hours. Should this not work, is there some way to tune the code so I can find said memory leak? Any help appreciated.

    Thanks.

    >NOTE: Just way too much code to upload... I'm having trouble pinpointing where said leak might be... <

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Its quite rare for a memory leak to occur by your code in PHP. It is possible a built in function is leaking though. Your assignments will be done via emalloc calls, which PHP tracks and terminates at the end of script calls. So the question is if you are seeing leaks from the PHP code itself not releasing, or from something else.
    There are a lot of potential issues to which could be the cause. There have been known leaks in the PHP code itself as well. I'd check if there's a list of php executables running in the ps list. If there are not, you should verify the handler for the apache and PHP are correct. I haven't done a linux install in years, but the apache library at least with windows has moved to the apachelounge and you need a different handler for the module in each of the newer versions (previous ones were backwards compatible for many versions from what I recall).
    So. . . if you have lots of php executables, then I'd blame your code or a call to something leaking in PHP land (via fcgi build).
    If you see a lot of memory on httpd, than I'd say it's between the PHP executable and the apache module and probably not directly caused by the code. Some modules like oracle and memcache have been known to be more problematic than others.
    Unfortunately, this is really more of a question for lower level developers and OS experts. I don't even know where I'd start to identify a memory leak in httpd/php modules.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    171
    Thanks
    3
    Thanked 10 Times in 9 Posts
    Thanks for the hints. Addressing #2 above, I now have a situation where /var/www/httpdocs is owned by <user>:psaserv and everything else under it is owned by <user>:psacln.

    We've had no slowdowns for 18+ hours. Watching the httpd processes, one will occasionally hit 1.5% (compared to the 40+% I was seeing when the system started slowing...).

    This, of course, is wonderful, but I am wondering how the owner:group really affects the script like that? Some google searching could not find any documentation as to how or why this is the problem.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    The only thing I can think of is a process trying to constantly access a file for which it's denied and it sits there waiting. Otherwise, I've never heard of that being a problem in the past either. It's also possible there is a looping condition matched (in PHP directly or in something external with it) that is awaiting for something like a file to be created/deleted which it didn't have privileges for. There's a lot of "possible" things you can take a guess at, but without really watching it closely I'm not sure if there's an after the fact method to determine that.
    Perhaps an infinite loop condition within the .htaccess for a redirect? Who knows.
    If you fixed it and its aok, then best to document what you did and move along. Try to revise it and determine when you have extra time otherwise you'll spend hours on something that could be only slightly related to your code.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    171
    Thanks
    3
    Thanked 10 Times in 9 Posts
    Quote Originally Posted by Fou-Lu View Post
    If you fixed it and its aok, then best to document what you did and move along. Try to revise it and determine when you have extra time otherwise you'll spend hours on something that could be only slightly related to your code.
    Exactly. I spent an hour looking further, then dropped it. It's working fine, no reason to waste time on a non-issue.

    Thanks.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yep
    *knock*wood*knock*

    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •