SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    525
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Too many connections

    At the weekend we kept getting the 'too many connections' error. I look at the open processes and it shows about 250 processes sleeping for long periods.
    Code:
    Id         | User   |  Host     | db   | Command | Time | State | Info             |
    +----------+--------+-----------+------+---------+------+-------+-----
    | 15160505 | myuser | localhost | mydb | Sleep   | 7308 |       |                  |
    etc... about 250 of them. Why is this? Is it a problem with mysql (maybe the configuration) or the php layer not closing connections? Things are normally absolutely fine. Could this be some kind of attack on our server? Seems unlikely as the open processes aren't actually doing anything.

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,068
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    PHP will normally close all database connections as the end of a scripts execution, unless your using permanent connections. Are you opening many database connections in a certain script?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    525
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    We're not using persistent connections, no. And each script opens only 1 database connection (I know it's only once as there's other stuff in the same include, which will cause an error if it's called twice).
    Maybe it's a one-off freak occurence, but I'd like to figure out why it was.

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Check the PHP error log, Apache error log and system logs around the same time and see if anything interesting turns up. This is a completely random guess, but if PHP was crashing with some kind of fatal error for some reason (like the kernel killing threads because the system is out of memory?), maybe the connections could be left hanging?

    You can minimize the impact of a connection not being closed for some reason by setting a low wait_timeout in MySQL.

    http://dev.mysql.com/doc/refman/5.0/...r_wait_timeout

  5. #5
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    525
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the responses. Sorry I really should have given more information. I think I panicked a bit!
    Yes I checked the php logs and they didn't yield any abnormal errors other than the failure to connect to the database. There were a fairly large number of occurences where the error was associated with a particular ip address. So first I though it was a DoS attack. But the connections are empty, and anyway the requests from this ip are only about 1 per second so that doesn't sound like DoS. More likely a robot that happened to stop by while the error was occurring (most other visitors would just leave when the see the site isn't working).
    I will check the wait_timeout value, though.

  6. #6
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    525
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    A few days after posting this the hard drives on my server failed in a catastrophic way. The first sign of trouble was that database connections were being left open. The server hosts are denying that the initial connection problems were caused by a problemative drive, blaming it on programming error.

    But I'm told that each connection on a linux server is a file. So if the hard drive was having problems, couldn't this also mean that files couldn't be removed and connections closed? Maybe I'm being fobbed off here. Anyone able to weigh in on this?

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That seems highly unlikely. I'm more inclined to agree with your host that they are unrelated.


Bookmarks

Posting Permissions

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