SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast Patrick Lucas's Avatar
    Join Date
    Dec 2001
    Location
    Ohio
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysqli - too many connections

    Hey,
    I just started using mysqli on my development server with PHP 5.1.6 and MySQL 5.0.27. We need mysqli to take advantage of some stored procedures that we've created.

    However, the problem is we get this error ever once in a while:
    PHP Code:
    Warningmysqli::mysqli() [function.mysqli-mysqli]: (00000/1040): Too many connections in init.php on line 38 
    It's especially annoying because once this error occurs, the MySQL server won't come back up. I have no idea how we're building up so many connections. We do call $mysqli->close() at the end of the scripts. We don't have any extremely intensive queries that get called a lot.

    It's a development server and it's not heavily trafficked. We have a whole box and probably only two or three people on it at a time. In php.ini I have mysqli.max_links = -1.

    I saw a really old thread dealing with this [link], but does anybody have any more recent experience with this?

    Thanks,

    Patrick
    Patrick Lucas

  2. #2
    SitePoint Addict Trent Reimer's Avatar
    Join Date
    Sep 2005
    Location
    Canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Patrick Lucas View Post
    In php.ini I have mysqli.max_links = -1.

    ...I saw a really old thread dealing with this
    In the old thread the bit about explicitly freeing results was interesting.

    I notice one thing everyone has in common is the setting:
    Code:
    mysqli.max_links = -1
    Would the database prefer a cap on that setting?

  3. #3
    SitePoint Addict Trent Reimer's Avatar
    Join Date
    Sep 2005
    Location
    Canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If PHP is not going to cap the number of connections, then you need to ensure that your database allows at least as many simultaneous connections as your web server allows worker threads. Although unless you're using persistent connections I can't imagine such a low-traffic server ever eating up the entire pool of connections even if the web server allows more worker threads than the database server allows connections.
    PHP questions? RTFM
    MySQL questions? RTFM

  5. #5
    SitePoint Enthusiast Patrick Lucas's Avatar
    Join Date
    Dec 2001
    Location
    Ohio
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    kromey: yeah, we're not using persistent connections. mysqli doesn't even allow them

    Trent Reimer: I actually did put in the free_results() thing, but it didn't fix the problem.

    I did find out why we're getting this error. The problem is that after we run any queries, we're getting a bunch of connections that don't go away and just "sleep." That's how it's building up.
    Patrick Lucas


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
  •