SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    united states
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a few questions concerning mysql_pconnect

    Hello

    I have been reading about mysql_pconnect (persistent connections) and I am a bit confused from the problems they seem to cause people.

    Here is what I understand:
    If I use mysql_pconnect instead of mysql_connect, then used connections from the same host, username & password will not be thrown away after the child process of the web server (I am using Apache) is done with them. They will persist for a whlie before being garbaged.
    This allows the child process to continue using the same connection if another request is made to the same host, username & password and the connection was still alive.

    I understand that many people are complaining that the number of persistent connections keep getting larger and larger.
    This is because the Web server spawns many child processes and each has its own connection.

    Here is my question:
    I all of the connections will be made to the same, username & password, can that problem still occur?

    I also understand that MySQL can limit the number of open connections. Is there a way to tell it not to limit it and what the cosequences of that would be?

    thanks in advance

  2. #2
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_pconnect() acts very much like mysql_connect() with two major differences.

    First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

    Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).

    The optional client_flags parameter became available in PHP 4.3.0.

    This type of link is therefore called 'persistent'.
    As you said, yes, the number of connection can get quite large. You can not tell apache to ignore the limit, this limit is set by the system administrator so you would need to talk to him and tell him to change it to whatever value you want (given that he is ready to change it).

    Hope this clears something...
    - website

  3. #3
    SitePoint Addict CandyMann_69's Avatar
    Join Date
    Jun 2003
    Location
    Phoenix, AZ
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried using pconnect and see what it does? My understanding is that it will just use one connections and keep using it.

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    united states
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is pconnect the only way to work with connection pooling in PHP?
    Is it possible to find other solutions (possibly written by other people)
    or do I have to rely on the Web server implementation in either case?

  5. #5
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I believe that you'd need to rely and PHP and MySQL to do this, I don't know that a scripted solution could handle a task like that. mysql_pconnect doesn't usually pose any problems, shared hosting sysadmins usually set the timeout of persistant connects to a very short period and if you have a dedicated server, it shouldn't be a problem at all.


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
  •