NYCPHP Meetup

NYPHP.org

[nycphp-talk] When to close a mysql connection

Adrian Noland anoland at indigente.net
Mon Jul 2 12:11:14 EDT 2007


Persistent connections need to be used with care.

The following article explains some problems:
http://www.mysqlperformanceblog.com/2006/11/12/are-php-persistent-connections-evil/

Additionally, the default configurations for PHP, Apache and MySQL don't
lend themselves well to persistent connections. One disparity that will bite
you in the end is the default timeout to close the connection. MySQL's
default timeout is 8 hours. The expected environment is a desktop client
that will re-use the same connection again and again. HTTP does not work the
same way. If you wind up with several orphaned connections to the DB server
they will just sit around waiting for nothing until the connection times
out. This will use up all your available connections.

Another configuration issue is the number of MySQL connections need to match
the number of threads/processes configured for Apache.

http://us.php.net/manual/en/features.persistent-connections.php
"You are probably using a multi-process web server such as Apache. Since
database connections cannot be shared among different processes a new
one is created if the request happen to come to a different web server
child process."

Adrian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070702/805d71ec/attachment.html>


More information about the talk mailing list