Page 1 of 1
what /when to use mysql_pconnect?
Posted: Thu Jun 29, 2006 12:15 am
by pelegk2
when should i use mysql_pconnect and when to use mysql_connect
?
what the execlly diffrence and how does it influence performance?
thnaks in advance
peleg
Posted: Thu Jun 29, 2006 12:23 am
by Robert Plank
mysql_pconnect: the connection doesn't terminate when the script ends.
If you don't know about stuff like J2EE connection pools you should stick with regular mysql_connect
can you please
Posted: Thu Jun 29, 2006 12:52 am
by pelegk2
maybe reffer to an article that explains the diffrence or maybe explain in some simple words?
Posted: Thu Jun 29, 2006 4:46 am
by Jenk
I've used persistant connections (in connection pools) with other languages, but am yet to find myself needing to use it in PHP.
The short answer, which doesn't help, is: "Only when you need to use a persistant connection" :p
I do know of Yahoo! sized sites using connection pools in PHP (thus use mysql_pconnect,) but due to the nature in which PHP operates, I'm not sure on how they achieve the same result as using a connection pool ala J2EE. Simply because PHP is a Script-language and only operates on a request basis.. i.e. your send a request, it responds then terminates.
Unless there is a side to PHP I am oblivious to.
The differences are quite simple, but the implications, and reasons to use either over the other are not so simple:
mysql_connect - connection is made and is automagically closed upon script termination.
mysql_pconnect - connection is made, and is only closed when mysql_close is called (and the relevant connection identifier used.) The engine will actively maintain this connection so it does not close, until a preset timeout period expires, or the mysql_close command used.