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.
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.
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.
"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.
Bookmarks