SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast Ckeren's Avatar
    Join Date
    Jun 2001
    Location
    AU
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    which one is the best mysql_pconnect or mysql_connect ?

    well I must say the usage in terms of security.

  2. #2
    SitePoint Enthusiast Stallion's Avatar
    Join Date
    Jan 2001
    Location
    Cumberland, RI, US
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's no difference, security wise.

    However, there is still a difference. ;-)

    If your MySQL server is hosted on the same machine as your web server, or on a machine connected via a high speed LAN, you want mysql_connect(). Otherwise, if you're connecting from a computer in Boston to a computer in New York, you'd want mysql_pconnect().

    Its a general rule, but a good guideline for usage.

  3. #3
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Stallion
    If your MySQL server is hosted on the same machine as your web server, or on a machine connected via a high speed LAN, you want mysql_connect(). Otherwise, if you're connecting from a computer in Boston to a computer in New York, you'd want mysql_pconnect().
    Why is that? A lot of the overhead involved with querying the DB is actually just connecting, so it would work well on a LAN or localhost too.

    I think that a better guideline would be that if you're going to be running lots of queries on your DB, then you should use pconnect. If you are only going to be querying your DB a few times a day, then use connect.

  4. #4
    SitePoint Enthusiast Ckeren's Avatar
    Join Date
    Jun 2001
    Location
    AU
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well what about in terms of execution speed ? which one is slower if lets say every 30 Minuts requesting for data.

  5. #5
    SitePoint Enthusiast Stallion's Avatar
    Join Date
    Jan 2001
    Location
    Cumberland, RI, US
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    qslack: there's a big overhead of the idling processes

    Search on Google for "pconnect php mysql" and I'm sure you'll find some better explanations.

    Ckerken: they're both about the same. The real bottleneck, if there is any, would be in the actual queries you're executing.

  6. #6
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i benchmarked the 2 on my machine here w/ no load on MySQL (it's just idle) and here's the (average) execution times running the same query:

    connect = 0.0102 seconds
    pconnect = 0.0033 seconds

    i assume that the busier MySQL is the longer it will take to get a connection with connect.

  7. #7
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    The reason for mysql_pconnect(); is when a site has a ton of hits in a short amount of time. Because disconnecting and reconnecting can cause a lot of overhead in this type of situation mysql_pconnect(); keeps the connection open at all times and does not disconnect. So not as much overhead as with a lot of hits.

  8. #8
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Straight from the horse's mouth at php.net:

    "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()).

    "This type of links is therefore called 'persistent'."

    Also note on that page how some user comments have said that pconnect is much slower than normal connect, however these people were running very busy sites. So I would say that pconnect is better for sites that are not that busy, but as sites are more and more busy it might be a good idea to use connect, that is just the feeling I got from reading the comments though
    http://www.php.net/manual/en/functio...l-pconnect.php

    Oh, and also, it kinda depends, cos if you query the database heaps and heaps etc, the times and performance are obviously going to vary, with the complexity of you queries as well.
    Last edited by timnz; Jul 7, 2001 at 20:10.


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
  •