SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My understanding is that if the script has to connect to the DB quite often, using pconnect() should be more appropriate.
    Does mysql_pconnnect() differentiate between connections from this or another machine? Since in the documetation, it said it finds some connection already made, but does that connection have to be from the same client or same script?
    Thanks
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    mysql_pconnect() does not differentiate between connections based on the client IP or any other information. All it does is create a connection to the MySQL server that will not be closed when the script terminates, so the next time a script calls mysql_pconnect() with the same arguments (MySQL server, username, password), the existing connection will be used instead of a new one being created.

    Doesn't matter what script or client is using the connection.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot Kevin,
    I think I did recognize the difference in performance when I change that
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    SitePoint Evangelist mad-onion's Avatar
    Join Date
    Aug 2000
    Location
    Land of the long white cloud
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A question for Kevin on this issue..

    Is it more intensive on server resources to use p_connect or is it possibly the complete opposite?
    I have never used this, even knowing what it did, because i never really understood what the positve/negatives are of persistant connections...could you enlightne me?

    TIA
    SiteOptions >> Services :: Products :: Contact
    Developers of PHP, C++, Visual Basic, MySQL, and more!

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Using mysql_pconnect() will save PHP the trouble of opening a new connection to your MySQL server to service every client request, so in that sense it definitely saves time. So if you consider time a server resource, then it definitely saves resources.

    There aren't any real downsides to using persistent connections, except that they will not work on the CGI version of PHP. Since a new PHP process is created for every client request, the MySQL connection dies with the PHP process at the end of the request.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  6. #6
    SitePoint Evangelist mad-onion's Avatar
    Join Date
    Aug 2000
    Location
    Land of the long white cloud
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that Kevin.

    You are a legend!
    SiteOptions >> Services :: Products :: Contact
    Developers of PHP, C++, Visual Basic, MySQL, and more!


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
  •