mysql_connect vs mysql_pconnect

Mysql_connect() and mysql_pconnect() are both used to open a connection with mysql database.

But there are 2 main differences between mysql_connect() and mysql_pconnect()
1. mysql_pconnect() first tries to find and existing connection from same host and user, if connection found then that connection is used.
2. mysql_pconnect() opens a persistent connection with database and connection does not closes even after script finishes it’s execution.

pconnects are expensive in RAM. Make sure you have enough to handle all the children you need and you’re ok. If you don’t your database server will grind to a halt and die under load.

pconnects can raise no. of connection drastically but it will decrease the time to load page.

if you are using an shared server and your website is highly database oriented then you should never use mysql_pconnect. it will soon become unmanageable. in this scenario you should use mysql_connect() as it closes the connection automatically after execution of script.

if you are using a dedicated server and you website do not heavily depends on database then you can use mysql_pconnect() to make your site load faster.