[nycphp-talk] When to close a mysql connection
Jakob Buchgraber
jakob.buchgraber at googlemail.com
Sun Jul 1 06:28:12 EDT 2007
> I am in no position to correct you, but isn't it that PHP talks to MySQL
> rather then the HTTP client? As far as MySQL is concerned, the
> connection comes from where the PHP interpreter is located. And since
> each connection from PHP to MySQL gets named sufficiently uniquely I
> guess that PHP can keep multiple clients apart. Normally one opens a
> connection, runs the queries, and then closes it. I always make sure
> that I explicitly close the connection, but after reading the
> documentation a script end will close the connection as well. Seems to
> be quite different from opening files, which stay open and locked even
> after the script is done.
> It may just be that PHP uses only one persistent connection and feeds
> all the queries through that one regardless of client (but returns the
> values back to the script instance from where the query came), which is
> what you suspect. Unless someone who really knows what is going on comes
> forward we can only resort to speculation.
>
> I will give it a try and see what happens. It's only adding a "p". Since
> the mysql_close doesn't do any thing on persistent connections there is
> no harm in leaving it in - or so the theory goes.
>
> I don't see a problem with my current project as this one will never be
> used by more than a few dozen clients at a time, but I have other
> projects where some optimization may be more than just OK.
>
>
> 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
>
Exactly that's what I tried telling you :-D. Of course the HTTP Client
(=user) does not connect to mysql it's the PHP script, but the PHP
script gets executed when the client makes a request and regardless how
many requests he makes the PHP Script/Mysql does not know that this user
has already been here. That's what I wanted to tell you as I thought
that you thought that persistent connections mean that for every user a
new connection is opened and that each connection corresponds to a user
and is kept open for e.g. 30 minutes, but that's not true.
Anyway, it seems to mean that you got it now and that's actually
everything that counts.
- Jakob
--
Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0
More information about the talk
mailing list