NYCPHP Meetup

NYPHP.org

[nycphp-talk] When to close a mysql connection

Jakob Buchgraber jakob.buchgraber at googlemail.com
Sat Jun 30 20:28:32 EDT 2007


David Krings wrote:
> Jakob Buchgraber wrote:
>  > No mysql doesn't hold many connections then as there is only one
>> connection at all when using persistent connections.
>>
> Well, yes, but I assume one per client. So if I'd set the timeout to be 
> x hours then it might just be quite easy to pile up a few hundred of 
> unused connections. And that even with only a few concurrent connections 
> at a time. Playing devil's advocate here.
> 
> I think that this might be less an issue when setting the timeout 
> reasonably, such as 30 minutes. Much better to reconnect once every half 
> hour (if that) then for every script call. Is that how it works?
> 
> David
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 
No that's not how it works, that's how normal database connections work.
How should MySQL know which user connects? The user makes one HTTP 
Request and if he does it again nobody knows that he has ever been here 
(except if the webserver has set a cookie). I don't know how persistent 
connections exactly work as I haven't used them before. Everything I 
know and probably everything you need to know from a developers point of 
view is that when using persistent connections the connection is kept 
open even if the execution of the PHP script finishes and if the script 
is executed again and again there is always the same connection being 
used. If two scripts access this connection concurrently there is no 
second connection opened, no they are sharing this connection with each 
other.

That's actually how I understood it. So correct me if I am wrong ... :-)

- Jakob

-- 
Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0



More information about the talk mailing list