library

technical documents

Multiple php pools and their advantages

Posted by: Dan on August 29, 2007 04:45:15 AM +00:00
Multiple pools allow for flexible configuration.

poolsgravityEven though our preference is for Lighttpd and mod_fastcgi, these techniques will translate easily to other php-fastcgi implementations.

The Problem

One common problem with a busy site is performing administrative tasks, such as backing up the database, optimizing the tables, pruning posts in a forum to name a few. This is a problem because these tasks can tie up one or more php processes, thus slowing it down for everyone. Additionally, a production environment usually demands a low tolerance for "timeouts," such as a web server's keep-alive timeout or php's max-execution timeout.

The Solution

By running muliple php pools, you can tailor each one for the task at hand. For the main pool, serving the public site to anonymous and registered members alike, you might cut down the max_execution time to 10 seconds or less, from the default ini setting of 30 seconds. In the second pool, however, you can specify a much higer timeout, like 1200 seconds (that's 20 minutes), which should provide ample time for any long running administrative task to successfully finish.

lighttpd.conf

Here are some of the relevant settings to use in your custom lighttpd instance:

server.max-write-idle = 1200
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi-admin.socket",
"bin-path" => "/usr/local/bin/php-cgi -c /home/user/etc/php-admin.ini",
"max-procs" => 1,
"idle-timeout" => 1200,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "2",
"PHP_FCGI_MAX_REQUESTS" => "5000"),
"broken-scriptfilename" => "enable"
)
)
)

php.ini

Here are the relevant settings for your administrative php pool:

max_execution_time = 1200     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 64M ; Maximum amount of memory a script may consume (128MB)
Updated: 05 Apr 10 06:33