How to forwards on max_connections

Discussion in 'PHP' started by fgs, Dec 2, 2007.

  1. #1
    Hello,

    at time when opening the pages on my site you get the "max connections by user" php error in the queries..

    is there a way to forward to some error page if such error occurs?

    Thanks in advance
     
    fgs, Dec 2, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Something like:

    mysql_connect(PARAMTERS) or $error=mysql_error();

    Just match $error with the error you get when you have max connections and just header redirect.

    Peace,
     
    Barti1987, Dec 2, 2007 IP
  3. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It sounds as if your mysql server is running out of connections.

    Make sure you arent using pconnect and take a look at your my.conf file.

    You might want to increase max_connections

    Hope this helps
     
    tonybogs, Dec 3, 2007 IP
  4. fgs

    fgs Peon

    Messages:
    967
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the reply! my max connections where set to 0 aka unlimited ... but that was not doing the trick so i had it changed to some very large number.

    I will check on the pconnect. It is probably my poor coding job thought :mad:

    Thanks everyone for help
     
    fgs, Dec 3, 2007 IP
  5. l3vi

    l3vi Peon

    Messages:
    375
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Code yourself close for mysql, and also have the mysql config set to like 15 or 30 sec max connect to keep runaway scripts from staying open.
     
    l3vi, Dec 3, 2007 IP
  6. fgs

    fgs Peon

    Messages:
    967
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #6
    aren't all the connections closed automatically after the whole page is parsed in the newer php verisons?

    thanks for the suggestion though
     
    fgs, Dec 3, 2007 IP
  7. l3vi

    l3vi Peon

    Messages:
    375
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thats right, however not closing it bad coding habits, and it not a 100% that they close. For example you can start a page and kill the page and yet the SQL server will continue to run the query even after the script has closed down.

    I run a server that has more than 1 million inserts running per 1/2 min all day long.. its not that uncommon. You can sometimes see them as null sleeping threads in SQL.
     
    l3vi, Dec 3, 2007 IP
  8. fgs

    fgs Peon

    Messages:
    967
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks again, I do use
    <? mysql_close($link); ?>
    PHP:
    so that should not be the issue, i contacted dedicated host support and the max_connections setting and it was only set to 20.... so now I changed it to 100

    hopefully that will do the trick

    p.s.
    also, could you please send me a pm with your cost to look at one or two of the pages of my script and maybe help optimize the script, since I coded it myself with no previous knowledge of php/mysql
     
    fgs, Dec 3, 2007 IP
  9. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #9
    1 million inserts every half a minute for a whole day?

    Is that even possible on 1 mysql server? If so i am very interested to know your my.cnf settings and your server stats.
     
    tonybogs, Dec 4, 2007 IP
  10. l3vi

    l3vi Peon

    Messages:
    375
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #10
    fgs, sorry Im not for hire... tonybogs... my.cnf is really just a small part of your focus. We have max query times for queries are like 30s, and something like max threads of 200. On one box we have 9gb of ram and 80% of that is for mysql.

    You have to focus on your table designs, and queries. For example most people when they want to get a result count they will do something like SELECT count(*) as TotalResults FROM sometable WHERE something = ..... However this is the wrong way to go about it IMO. As mysql has to rip down the entire table to count all the rows, and like most script its then followed by yet another query to get the results. Its slow... so the mart way to get a row count is to do SQL_CALC_FOUND_ROWS.. eg SELECT SQL_CALC_FOUND_ROWS somefield, anotherfield FROM sometable WHERE something = ...... then after that has been run you run one more query to get the SQL_CALC with "SELECT FOUND_ROWS() AS TotalCount". Now your not raping the database to get a count, your just running a query for the results you want and then calculating the remaining rows.

    Other things are processing your raw data into another table, then loading the keys into memory. There are a million ways to go about it, its up to what you need.. However its all about your table designs and queries.

    Best,
    Levi

    ps.. sorry.. server stats... dual zion 3.6Ghz or something, 9gb ram.. a bunch of drive.. LOL memory is fuzzy, we just order anyother box if the load starts getting high(7-10), as we normally ride <2, but max at 5. ;p When you do that many inserts the insert table can not have anything but inserts running on it. You can also do like InnoDB depending on what the table is for.
     
    l3vi, Dec 5, 2007 IP