Php – How to cause php-fpm to kill it’s children after they are idle for a pre-defined period

PHPphp-fpm

I've got several low traffic vhost'ed applications that I'd like to run on the same box, using something like this configuration:

[example.com]
listen       = /tmp/example.com.socket
listen.owner = www-data
listen.group = www-data
listen.mode  = 0666

user  = www-data
group = www-data

pm                   = dynamic ; scale children according to this rule
pm.max_requests      = 1000    ; respawn child after so many requests
pm.max_children      = 12      ; cap the total number of children thus
pm.start_servers     = 6       ; children created at daemon boot
pm.max_spare_servers = 2       ; maximum number of idling children
pm.min_spare_servers = 1       ; minimum number of idling children

pm.status_path       = /php_pool_example.com_status

request_terminate_timeout = 30s
request_slowlog_timeout   = 20s
slowlog                   = /var/www/com/example/logs/php-slow.log

catch_workers_output = yes

env[HOSTNAME] = $HOSTNAME
env[TMP]      = /tmp
env[TMPDIR]   = /tmp
env[TEMP]     = /tmp

php_flag[display_errors]            = off
php_admin_value[error_log]          = /logs/php_err.log
php_admin_flag[log_errors]          = on

works okay, except that I'm not sure how to 'idle' a child so that php-fpm will kill it. The problem I'm seeing is that as I add more applications there exist ~6 idle php-fpm children per application, simply eating up RAM for no reason. Now, request_terminate_timeout will kill a child because of an over-long request, but not a child because of an overlong lack of requests. The manual defines how to say there are too many or too little idle children, but is quiet on designation. If I've measured that a php-fpm child which hasn't served a request for 30 minutes should be considered 'idle' and killed, how do I inform php-fpm of this?

Best Answer

The next stable version of php-fpm should support an ondemand scheduler that will scale children up and down. To date, there is no recourse.