Why it is impossible to to use mysql_pconnect() instead of mysql_connect() to get the maximum result of caching,
mysql_pconnect() Establishes a persistent connection to a MySQL server. then why mostly prefer mysql_connect() ?
Printable View
Why it is impossible to to use mysql_pconnect() instead of mysql_connect() to get the maximum result of caching,
mysql_pconnect() Establishes a persistent connection to a MySQL server. then why mostly prefer mysql_connect() ?
First and foremost,
# If at all possible, you should avoid using the mysql_* functions. #
Existing code should be updated to avoid performance and security problems. ext/mysql is outdated and has not been a recommended "best practice" since 2004.
Quote:
Originally Posted by php.net (official PHP website)
As for persistent connections,
They are still available, of course, when you use MySQLi or PDO, and you can use them if you want to. However, persistent connections don't always carry the benefits you expect them to. To start with, under Apache, a new process is usually spawned per request anyway, so there is no opportunity to re-use the connection. It will simply sit, idle, in its original process until Apache decides to kill it. In the meantime, MySQL is still devoting resources to it, and it's still in the connection pool so it still counts towards your maximum number of connections. If you have a moderately busy site (or a sudden spike in activity; maybe a hundred or so visitors at once), you can easily lock out your DB server.
Also, to clarify, persistent connections have nothing to do with "caching." They operate directly on the DB, like any other connection.
Read more.