SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem With Too Many Connections When Using PHP/MySQL

    Ok, I need the advice of the php gurus out there. One of the sites I do uses PHP and MySQL and is growing quickly. It is on a shared hosting plan that has a limit of 50 concurrent MySQL connections. Every once in a while I get the message:

    Warning: mysql_connect(): Too many connections in /data/sites/90572/microdaq.com/www/includes/mysql_connect.php on line 10 Failed to connect to the serverToo many connections

    ...which makes me think we are bumping up against the limit. When I contacted the host , the host questions if we are closing the connections after each query, which I haven't been doing. I have not been closing it in my script because on php.net it says "Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution". What I am wondering is should I be including mysql_close at the end of my mysql connection script?

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Your not using mysql_pconnect are you?

    Mark

  3. #3
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Definitely not. From what I read on php.net that would just add to the problem.

  4. #4
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I just wandered if you were using persistant connections, if that was the case you would have to close them after the query.

    Mark

  5. #5
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just as a manner of good programming practice, close all your connections when you're done with them.
    With enough hits/connection requests this may actually improve things.

    The site also may just be outgrowing the hosting plan.
    Another option would be to get a host which has a higher limit or the ability to adjust the cap (which of course will more than likely cost more money).
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  6. #6
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I am going to start using mysql_close. Here is a dumb question though, where do place it? I tried placing it in a few places and the connection gets closed before my php database functions work. I have 2 or 3 functions that are called on each page.


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
  •