mysql_connect VS. mysql_pconnect
Well, this should say enough. Which is better? I use pconnect AND connect in the same function. You can define to use it in my inc.connect.php function. Simply set TRUE to use it.
Now the question is, is it safer, faster, smarter, lighter... what is the advantage for real? If you guys can tell me, thanks. :)
Persistent connections are links that do not close when the execution of your script ends. When a persistent connection is requested, PHP checks if there's already an identical persistent connection (that remained open from earlier) - and if it exists, it uses it. If it does not exist, it creates the link. An 'identical' connection is a connection that was opened to the same host, with the same username and the same password (where applicable).
If persistent connections don't have any added functionality, what are they good for?
The answer here is extremely simple -- efficiency. Persistent connections are good if the overhead to create a link to your SQL server is high. Whether or not this overhead is really high depends on many factors.
There are some pre's and cons about persistent connections, you just have to read it for yourself
The Following User Says Thank You to sjaq For This Useful Post:
"The mysql_pconnect() function was designed to provide a mechanism for reducing the cost of establishing and closing connections to the MySQL server. Unfortunately, due to an interaction between the architecture of the Apache server and the architecture of PHP, high traffic on a site that used pconnects could quickly clog up the MySQL server with many unused connections that could prevent many of the active connections from accessing the database." Zak Greant