NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP and MySQL Connections

Hans Zaunere lists at zaunere.com
Sun Apr 20 13:26:41 EDT 2008


> >  I am by no means an expert, by I always close the connections
explicitly.
> > My understanding is that the connection gets closed eventually, but by
MySQL
> > itself after a time out period.
> 
> OK, that makes sense. I didn't want to do that just yet, because
> things have been running fairly well since I ditched persistent
> connections.

There are a couple of factors here.

-- when the Apache process actually terminates, because of Apache's process
settings

-- when the PHP script "shutsdown" which should typically mysql_close() the
connections to MySQL

-- when MySQL will kill a connection thread because of thread-reuse/caching
settings

> The curious thing is that MySQL doesn't seem to be cleaning them up. I
> checked last night, and there were some threads that had been in sleep
> for more than 7,000 (seconds?).

That does seem like a long time.  On the mysql server, do show variables
like '%thread%'; and show status like '%thread%';

See if anything looks out of wack as far as configuration and server stats
go.  Are these threads being reused (check the thread ID).

Is this a high-load server?  You may want to try to restart Apache - if this
then kills those threads from sleeping, you've isolated it to something in
Apache/PHP.  These aren't persistent connections right?  There was a bug
sometime ago in glibc (if I remember correctly) that prevented connections
from closing correctly, but this likely isn't the problem so double check
the PHP code/config.

H





More information about the talk mailing list