RE: pconnect doesn't appear to work properly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Let me start off by qualifying my remarks by saying I don't use persistent
connections, but I have researched them enough to know that I only need to
use a standard mysql_connect() to fulfill my requirements. That said, I
apologize for any unintended inaccuracies in my response.

>From the PHP manual:

"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()). 

The optional client_flags parameter became available in PHP 4.3.0. 

This type of link is therefore called 'persistent'."

So, if your visitors connect to the database with different connection
parameters (e.g., username, password, host, etc) that would partly explain
the multiple connections since each pconnect instance is unique to the
username/password/host combination.

As far as destroying the mysql_pconnect, I'm afraid I'm at a loss. The
documentation says that there is no way to destroy the persistent
connection. Maybe it is possible to set a duration for these pconnect
instances in the php.ini file to tell the garbage collection process to
destroy the link if it has not been used for a certain period of time?

I don't know how you're using the persistent connections in your
application, but you may want to check out what the PHP manual says about
persistent connections and their advantages and disadvantages (it's Chapter
23 in the CHM version I have, but I think my version is a bit old.) You
might find that you don't really need them at all and that a typical
mysql_connect() would do the trick. And mysql_connect() resources are
automatically closed when the calling script stops executing so you won't
have to worry about cleaning up after them.

Hope this helps.

> -----Original Message-----
> From: Ryan Hansen [mailto:ryan.hansen@usa.net]
> Sent: Thursday, October 02, 2003 11:41 AM
> To: php-db@lists.php.net
> Subject:  pconnect doesn't appear to work properly
> 
> 
> Gang:
> 
> We have noticed some considerable performance hits on our 
> server recently,
> and after some investigation, we found over 100 mysql 
> connections open and
> sleeping.  The process belonged, for the most part, to only 2 
> web sites,
> both of which use mysql_pconnect quite extensively.  After 
> watching it for a
> while, we noticed that each time a new pconnect was called, 
> it actually
> spawned a new connection rather than using an existing 
> connection.  Have any
> of you made similar observations?
> 
> Also, these open connections seem to stay open indefinitely.  
> Is there some
> way that we can optimize MySQL to close connections that have 
> been open and
> sleeping for a certain time?
> 
> We're running Apache 1.3.27 and PHP 4.2.2.
> 
> Thanks!
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux