Difference between Mysql connect & pconnect

In simple words. the difference between connect() and pconnect, it is simply like a shop when you entering in shop you will open the door and take your item, come out and close the door that is called connect() in mysql the connection to the mysql database will be automatically closed when the script terminates.
And when the door of the shop is already opend and never close it is called pconnect(), open a connection with mysql_pconnect(), the connection will not be closed and will “persist” for future use.

When to use pconnect:
- When PHP and Mysql are on different servers, in this case establishing connection takes time so its better to use pconnect. When PHP and Mysql are in same server then connection time is negligible so using connect or pconnect will not make much difference.
- When you know that there will not be lot of simultaneous requests to serve. Because in case when server is suppose to serve lots of request simultaneously then because of single connection Mysql server may get overloaded and can result a crash or server down problem.

Posted in:

Leave a Reply