what /when to use mysql_pconnect?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

what /when to use mysql_pconnect?

Post 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
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post 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
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

can you please

Post by pelegk2 »

maybe reffer to an article that explains the diffrence or maybe explain in some simple words?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
Post Reply