Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mysql_[p]connect

    If my site is designed to make a lot of database querys and practically all content is pulled out of the database, should I use mysql_pconnect or is it not much different from a normal connection? Also what exactly is the difference between these two functions?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    From http://uk.php.net/manual/en/function.mysql-pconnect.php
    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()).
    lalalalala apparantly my post is too short, just making it longer lalala

  • #3
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes I've read that but I'd like to know exactly what it does in simple baby language please. I Understand php.net's explanation but I can't help feeling they've missed something!

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did yu read the usercomments to? very usefull ...

    Anyway, using pconnect can burn quite a bit more RAM + there can be a fairly high number of sleeping threads. And you'll probably not have any noticable performance improvement.
    It doesn't matter that you pull all data from the db since each page only needs one connection .... What matters, and what would be a valid reason to use pconnect, is a high number on simultanious users.

    pconnect will look for a free connection (an established, not used connection --> thread) and will use that. Because of this, no new connection need to be made from the webserver to the mySQL server, which saves you a bit of time. If no free connection is found, a new one is created.
    If trafic drops, then a number of unused connections will remain open, so you need to clean up from time to time. Else these redundant open connections will just spill memory resources, which might actually slow down other processes.

    With regular connections, the connection is closed when the script ends.

    Bottom line --> use non-persistent connections, unless you have a high number of simultanious users. and even then, monitor it closely to see if it realy improves responsetimes
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks raf, I'll wait till I start getting a few more hits then.

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    all the reasons to avoid persistant conncetions under most circumstances >> http://au3.php.net/manual/en/feature...onnections.php
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •