[wp-hackers] Closing Mysql connections

Dion Hulse (dd32) wordpress at dd32.id.au
Fri Mar 19 12:57:42 UTC 2010


The reason for this is quite simple. WordPress uses the database  
throughout the execution of the script, It's needed until shutdown as  
you'd expect.

WordPress relies upon PHP's inbuilt memory garbage collection for freeing  
memory and closing the MySQL handle. See http://au.php.net/mysql_close for  
a description of that.

In short: Closing of the connection is handled by PHP, the script shouldnt  
have to call it. The only time its needed to be called, is if the database  
link is known to be no longer of use to the script, and it'll be running  
for awhile longer (ie. number crunching)

adding it to the shutdown hook would suffice to see if it makes a  
difference for you.
Chances are(Well, Possibility?), if its a high traffic site, you're just  
seeing the connections that are being used at that very moment, reload and  
you're probably looking at a entirely new set of connections?


On Sat, 20 Mar 2010 01:49:58 +1200, Andrew Gray <andrew at graymerica.com>  
wrote:
> I will start with the statement that this wordpress site is on a server  
> where I do not get to control apache or mysql.  It is at Rackspace  
> Sites, which is a LAMP stack where you only get FTP access.  I get a ton  
> of traffic and I am running into max mysql connection errors.   My max  
> user connections is set at 500.  I really want to stay on this platform  
> because of the support I get there and the price.  My traffic profile is  
> unique and I have all the caching I can use.
>
>  Im trying to figure out why there is no call to mysql_close anywhere in  
> wordpress.
>
> Is it just assuming that the connection will be automatically closed  
> when the script ends?


More information about the wp-hackers mailing list