Results 1 to 13 of 13

Thread: Warning: Too many connections.....

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    Warning: Too many connections.....

    I am developing a site using PHP with Dreamweaver MX and connecting to a MySQL db on a Red Hat (linux). After so many hits to my site I get funky errors like Warning: Too many connections in /home/virtual/siteXX/fst/var/www/html/Connections/domain_name.php on line X Too many connections.

    Yes, I understand that each page that is loaded is starting a connection but at the end of each page Dreamweaver MX releases it by doing a
    PHP Code:
    mysql_free_result($recordset); 
    for each recordset.

    We had success with our code for a over 6 months but all of a sudden after a upgrade to the box we keep getting this and our fix is to stop and restart the MySQL server ever so often.

    Do we have a setting we need to change? I thought PHP would handle the closing the connection automatically? If this is wrong then Dreamweaver MX has a flaw in its code.

    Thanks for any advice anyone can provide on this issue.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Code:
    mysql_free_result($recordset);
    Is redundant, especially if you do it at the end of the page, as PHP frees the result when the script finishes executing.

    There is a variable you can change in MySQL called max_connections. The default is 100. I'm not sure what would be safe to raise it to.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830
    Yes, we are aware of this but it is a temp fix because it will still happen just not as often.

    Thanks!

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I've never heard of this happening before. What version are you running?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    releasing it only works if the connection gets a big query. what you want is mysql_close() as that closes the connections, hence that is your problem

  6. #6
    Lively Member
    Join Date
    Sep 2002
    Location
    Newfoundland
    Posts
    71
    The error points to overloading your MySQL server. Too many people are trying to get data from the server at once. There are 3 main solutions

    1) As 'The Hobo' alluded to, you can change the max_connections directive. If you set it to 0, then there will be no limit on the number of concurrent connections. If you can do this, and you have a reasonable server, then everything will work out.

    2) I'm not too familliar with persistent connections (mysql_pconnect()). Maybe that will work?

    3) Only open a MySQL connection when you absolutely need it. Don't open it at the beginning of every page and close it at the end....Open the connection, do your query, close the connection and then do the operations with the MySQL recordset that you need to. This also works well.
    - Adam Lundrigan

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    mysql_close error

    Still having my connection issues. phpman, in response to your mysql_close(), I tried this and get an error.

    Is anyone familar with the following error message?

    PHP Code:
    Warningmysql_close(): xx is not a valid MySQL-Link resource in /dir/html/htmlpagename.php on line xxx 
    After the:
    mysql_free_result($connection);
    I put:
    mysql_close($connection);
    and I get the error above.

    Any ideas why? Do I have something set up incorrectly?

    --------------------------------
    FIXED

    Sorry, I guess I was closing the recordset not the connection. That does help
    Last edited by lleemon; Sep 15th, 2003 at 12:55 PM.

  8. #8
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    all you have to do is

    mysql_close();

    and that is it, no variable or anything. unless of course you have more than 1 connection to different databases.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830
    Is there a difference between these in performance, etc...?
    mysql_close(); vs mysql_close($connection);

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    I don't believe so, but why have a variable in it if you don't have to?

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    I don't believe so, but why have a variable in it if you don't have to?
    Readability. If somebody not very familiar with PHP was browsing through your code, that might help them figure out what is going on.

    But if that's not the case...why bother?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    if you dont include the variable then it will close the last open connection, which would be okay for a simple page, but if you are trying to make lots and lots of connections, for some reason, then i suppose its just to make things cleaner? or not?

  13. #13
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by john tindell
    if you dont include the variable
    Being the nonsegratory and nonracist person that I am, I try to include my variables in the same activities as all the other language constructs.


    PS: I appologize if "segratory" is not a word. It just sounded cool.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width