04-14-2004, 11:12 AM
If my site is designed to make a lot of database querys and practically all content is pulled out of the database, should I use mysql_pconnect or is it not much different from a normal connection? Also what exactly is the difference between these two functions?
04-14-2004, 12:45 PM
mysql_pconnect() acts very much like mysql_connect() with two major differences.
First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).
lalalalala apparantly my post is too short, just making it longer lalala
04-14-2004, 06:23 PM
Yes I've read that :rolleyes: but I'd like to know exactly what it does in simple baby language please. I Understand php.net's explanation but I can't help feeling they've missed something!
Did yu read the usercomments to? very usefull ...
Anyway, using pconnect can burn quite a bit more RAM + there can be a fairly high number of sleeping threads. And you'll probably not have any noticable performance improvement.
It doesn't matter that you pull all data from the db since each page only needs one connection .... What matters, and what would be a valid reason to use pconnect, is a high number on simultanious users.
pconnect will look for a free connection (an established, not used connection --> thread) and will use that. Because of this, no new connection need to be made from the webserver to the mySQL server, which saves you a bit of time. If no free connection is found, a new one is created.
If trafic drops, then a number of unused connections will remain open, so you need to clean up from time to time. Else these redundant open connections will just spill memory resources, which might actually slow down other processes.
With regular connections, the connection is closed when the script ends.
Bottom line --> use non-persistent connections, unless you have a high number of simultanious users. and even then, monitor it closely to see if it realy improves responsetimes
04-14-2004, 09:46 PM
Thanks raf, I'll wait till I start getting a few more hits then.
04-15-2004, 11:21 AM
all the reasons to avoid persistant conncetions under most circumstances >> http://au3.php.net/manual/en/features.persistent-connections.php