SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Persistant connection

    <b>Warning</b>: mysql_pconnect() [<a href='function.mysql-pconnect'>function.mysql-pconnect</a>]: User source_core already has more than 'max_user_connections' active connections in <b>/home/source/public_html/lib/php/tru/database/mysql/connection.php</b> on line <b>68</b><br />

    On our new server we experienced this issue. this makes ZERO sense because we use persistant connections everywhere on our site. There's nowhere that doesn't use it.

    i got this error in an email when a few crons failed to run... any ideas on what could be causing this with a persistent connection?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just because you use persistant connections doesn't mean you only ever have one connection to the database.
    http://www.php.net/manual/en/feature...onnections.php

    Much depends on the webserver, its configuration, and how you use it to run php. Cron jobs may, or may not be executing php through the webserver. If not, you won't be getting any of those persistent connections from the webserver.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it bad if we increase the number of connections?

    I don't see an option in the WHM for my server to increase the number of sql connections, I take it it's in apache somewhere?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    max_user_connections is a mysql setting.

    reducing the number of child processes apache uses would help in this aspect, but that might not be a good idea for other reasons.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do I even have any other options than increasing this number?

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't want to adjust the webservers configuration to alter it's behavior of the child processes, and you insist on using persistant connections(why?), you probably need to increase max_user_connections.

  7. #7
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Based on my understanding of persistent connections there's no reason to use a regular connection. Instead of closing it when the page finished it leaves it open and reuses the connection again. Why would I want to close/open every page load?

  8. #8
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To elaborate on my understanding....

    I understood Persistent Connections to be a connection in which it could be used endlessly on a busier site. IE - if we have a connection lets call it "forums" and it's persistent, then every user who checks the forums would utilize that single connection.

    Am I incorrect in this and it's more like the connection stays open for each unique user?

  9. #9
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Did you read the documentation crmalibu provided in post #2? It seems to answer everything your asking here.

    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  10. #10
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've read it but I suppose I'm not fully understanding either the documentation or the situation. Because what I read in the docs is that it does utilize any open connections, so why is my server saying there aren't enough max connections available if pconnect should use an existing one?

    Essentially, we just moved to a dedicated server and I got an error saying the max number of connections has been reached. I've since increased the number from 500 to 1,000. Now that I've temporarily solved the problem I need to be sure this isn't a bad solution and need to see if I need to make other adjustments to our configuration. Even if it means not using a persistent connection.

  11. #11
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The thing is it will utilize an open connection if it can find one for the current process. There's different ways apache can be setup, but a rough overview:

    There is an apache parent process. This parent process creates and manages apache child processes. These child processes are the ones which actually do the work of serving the http request(running the php script, serving the image/css files etc...). You will have many of these child processes at any given time, some sitting idle waiting for the parent process to give it an http request so it can do some work.

    The children are independent of each other. So, if a persistent database connection is opened in one of the child processes, none of those other child processes will ever know about it. That connection is specific to that child. So, each child will likely open its own persistent connection sooner or later when it happens to run a certain php script, and it will hold onto it until the child is destroyed by the parent(which may never happen depending on apache config, or the children may be destroyed frequently(like every 100 requests)).

    A cron job which executes php by using wget on a url, will make php execute in one of the webserver child processes, so it may get lucky and happen to be a process which already has a connection. A cron job which executes php directly(like /usr/bin/php myscript.php) will launch its own process. It's a brand new process, and so there's no hope of php finding an existing persistant connection. So it will open a new one.

    Hopefully you can see how you won't have just one connection, but you will have many open at the same time. Still, exceeding 500 connections sounds a bit much to me...I wonder if maybe some connections aren't being closed if/when a process dies. I'm not sure how or if mysql is notified of a closed persistent connection when a process exits. If mysql simply relies on a timeout, that could easy cause you huge numbers of open connections.

  12. #12
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see what you're saying now about the processes.... I know I have a lot to learn, but I need to start with MySQL connections it appears.

  13. #13
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    :sigh: still getting this error, our site isn't even that busy and we're getting these errors so there's got to be something hugely wrong.

    Does each query on a pageload run it's own process or something? With a 1,000 max connections we're still experiencing issues...


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
  •