View Full Version : mysql_pconnect()
FancyToy
10-16-2000, 10:18 PM
Hi,
So, you do not allow persistent connections.
I guess you fear that you could have thousands of open connections pegging your MySQL instances and I understand.
Now, what will I happen if I use the mysql_pconnect() API anyway? Will a connection be established per interaction or will my script simply fail?
Thank you for your attention.
Regards,
FancyToy
Terra
10-16-2000, 10:29 PM
You can still use the mysql_pconnect, but it will be treated as a regular connect...
Just make sure that when you are done with the connection, to close it out...[nbsp][nbsp]Many people forget to do this and depend on the MySQL server to do it for them...[nbsp][nbsp]This is why there is a 300 second timeout on all connections, otherwise the more greedy ones would slurp up the 255 connection slots in the blink of an eye...
If everyone would close their connections and check return values for errors, then many overload problems would be solved on the MySQL servers...
--
Terra
--Laziness in programmers is a virtue, not a right--
FutureQuest
FancyToy
10-16-2000, 10:49 PM
Thanks!
I am a very very cautious developer.
I would never let a connection hang loose. ;-0
FancyToy
PaulKroll
10-20-2000, 01:36 AM
PHP's official docs say the mysql_close is usually not needed because at the end of the script, non-persistent connections are closed.[nbsp][nbsp]Is this not the case in reality?
Actually, what I'm fearing is the other part of the page http://www.php.net/manual/function.mysql-close.php which points out that mysql_close doesn't do anything to a persistent link... OK, great, but if you connect w/mysql_pconnect, with persistent links not active, and then do mysql_close or just end the script, does php just leave the connection hanging on the assumption that the link WAS persistent, or does it do the close? Given the number of scripts that come "out of the box" w/mysql_pconnect, if this isn't handled right it could account for a great many timed out connections.
I'd love to say I had confidence that this was being handled "properly" by PHP, but... :)
Justin
10-20-2000, 04:54 AM
When you disable persistant connections in PHP, mysql_pconnect() behaves exactly like mysql_connect() does, including connections being closed automatically.
While it's not absolutely necessary to close your connections, it is still good practice to do so. It's not necessary to close your <HTML> tag, or tags, or <OPTION> tags, but we still do. It's just proper coding, as you will find that not all situations will work correctly with all methods of coding practice -- so it's best to explicitly close your connections rather than depending on the fact that the current version happens to do this for you...
At any rate, it is correct that they will be closed when the PHP script exits (assuming it exits *properly*).
------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support
vBulletin® v3.6.8, Copyright ©2000-2009, Jelsoft Enterprises Ltd.