max user connection

Discussion in 'MySQL' started by 1ahosting, Oct 27, 2006.

  1. #1
    Hi,
    My site always gets this error:

    Warning: mysql_connect(): User mydb has already more than 'max_user_connections' active connections in /home/myusername/public_html/config.php on line 7
    User mydb has already more than 'max_user_connections' active connections

    I checked with my programmer, he said the current max user connection is set to 20. How come i get this data access error? i'm loosing tons of users each day because of this error.

    People using forums site, they have 100's of people online every minute, my sites get 20 people and it starts giving above error.

    Any solution for this?
     
    1ahosting, Oct 27, 2006 IP
  2. dkalweit

    dkalweit Well-Known Member

    Messages:
    520
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    150
    #2
    Uh.... Tell your programmer to up the max user connection setting? He should have proposed doing so when youa sked about it...



    --
    Derek
     
    dkalweit, Oct 27, 2006 IP
  3. seojunkie

    seojunkie Banned

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Closing your connecton explicitly is always a good practice. :)

    If you ask me, he should use pconnect instead of connect. OR explicitly close your connection when you are done at the end of each page.
     
    seojunkie, Oct 27, 2006 IP
  4. 1ahosting

    1ahosting Peon

    Messages:
    199
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    he did mention that, but he also mention cons, that server load will be high since more people using the site.

    pconnect?

    explicity, i think thats already being done for closeing the connection. YOu think maybe couple of pages may have been left out that are not closing the connection?
     
    1ahosting, Oct 27, 2006 IP
  5. 1ahosting

    1ahosting Peon

    Messages:
    199
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i was looking on pconnect, it looks same, but it sats open till user browsing, but dont you think once certain amount of user reached, it will give the above error?
     
    1ahosting, Oct 27, 2006 IP
  6. rb3m

    rb3m Peon

    Messages:
    192
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    When you load a page from a forum or whatever the webserver asks the database for a user, then retrieves some information and sends the results to the client. Once this is done (and it usually takes a fraction of a second) there's no reason to keep that connection to the database open. What's happening here is that the connection is not being closed, it remains open and a new one is open with each new user. Obviously those 20 alloted spaces for users are not going to last long like that.

    So, at the end of each page tell php to close the connection to the database and it will be freed for a new user. Php keeps track of all the different remote clients, so no information will be mixed.

    Since each connection only remains open for a fraction of a second each time, those 20 connections can stretch a lot further.
     
    rb3m, Oct 27, 2006 IP
  7. Estevan

    Estevan Peon

    Messages:
    120
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    0
    #7
    pico /etc/php.ini
    [MySQL]
    ; Allow or prevent persistent links.
    mysql.allow_persistent = On => Off

    pico /etc/my.cnf
    set-variable = max_connections=250
    # good to stop kids to play
    skip-networking

    # i use this but configure based in your hardware
    key_buffer = 16M
    myisam_sort_buffer_size = 64M
    join_buffer_size = 2M
    read_buffer_size = 2M
    sort_buffer_size = 3M
    table_cache = 1500
    thread_cache_size = 128
    wait_timeout = 15
    connect_timeout = 10
    max_allowed_packet = 1M
    max_connect_errors = 10
    query_cache_limit = 1M
    query_cache_size = 16M
    query_cache_type = 1
     
    Estevan, Oct 28, 2006 IP
  8. 1ahosting

    1ahosting Peon

    Messages:
    199
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8

    aha, it makes sense now. I'll get someone to check if each page has connection closing.
     
    1ahosting, Oct 28, 2006 IP