Weblog entry #246 for simonw
#246
MySQL Persistent Connections in PHP
Posted by simonw on Tue 6 May 2008 at 15:11
The switch for disabling these for PHP scripts is not "mysql.cnf" as some non-Debian hints suggest but "/etc/php5/apache2/php.ini" on Debian (adjust for PHP and Apache versions as applicable).
You might consider this if you seem to accumulate a lot of lurking MySQL processes from web applications that use the pconnect call in PHP, and you thus hit problems with too many connections.
mysql.allow_persistent=Off
Similar setting can be set for various different databases (Postgres, ODBC etc).
Persistent connections allow a resource optimisation, but allowing them permits users to more easily hit the resource constraint "Too many connections in ...", depending on programmer skill.
Unless the same database connections are heavily used, disabling it makes the system administrators life easier (and in our case things run faster, probably as the so many fewer tasks have to be scheduled!). So assume your PHP programmers are brain dead, and disable it till you learn otherwise, and life may be better.
In this instance I am probably the brain dead PHP programmer, although there are a lot of clueless PHP programmers so it might not have been me, and this was in generated code anyway so I probably clicked the wrong button in a point and drool tool somewhere.
This is a note for self. If I understood all this - I wouldn't have hit this problem.
You might consider this if you seem to accumulate a lot of lurking MySQL processes from web applications that use the pconnect call in PHP, and you thus hit problems with too many connections.
mysql.allow_persistent=Off
Similar setting can be set for various different databases (Postgres, ODBC etc).
Persistent connections allow a resource optimisation, but allowing them permits users to more easily hit the resource constraint "Too many connections in ...", depending on programmer skill.
Unless the same database connections are heavily used, disabling it makes the system administrators life easier (and in our case things run faster, probably as the so many fewer tasks have to be scheduled!). So assume your PHP programmers are brain dead, and disable it till you learn otherwise, and life may be better.
In this instance I am probably the brain dead PHP programmer, although there are a lot of clueless PHP programmers so it might not have been me, and this was in generated code anyway so I probably clicked the wrong button in a point and drool tool somewhere.
This is a note for self. If I understood all this - I wouldn't have hit this problem.
Comments on this Entry
In your mysql.cnf, what value do you have for max_connections? It defaults to a fairly low number (I think 100), so you can probably up it a bit.
See http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html for more info. From the page:
"The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform. Linux or Solaris should be able to support 500-1000 simultaneous connections, depending on how much RAM you have and what your clients are doing. Static Linux binaries provided by MySQL AB can support up to 4000 connections."
See http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html for more info. From the page:
"The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform. Linux or Solaris should be able to support 500-1000 simultaneous connections, depending on how much RAM you have and what your clients are doing. Static Linux binaries provided by MySQL AB can support up to 4000 connections."
[ Parent | Reply to this comment ]