Cleanest configuration for the new PHP-FPM?
When examining the PHP-FPM configuration, I realized that I only tweak a few key pieces per pool, so I decided to share my approach to minimize redundancy and keep things simple (more files, but simpler to manage)
Because I still have to maintain PHP 5.2.x for clients, I have decided to try building everything in self-contained in an /opt/php53 directory. So consider that my $prefix, and change appropriately.
I have the following setup, and it seems to work great so far.
/opt/php53/etc/php-fpm.conf:
[global] log_level = notice error_log = /opt/php53/var/log/php-fpm.log pid = /opt/php53/var/run/php-fpm.pid emergency_restart_threshold = 10 emergency_restart_interval = 1m process_control_timeout = 5s daemonize = yes ; pools include = /opt/php53/etc/fpm.d/pools/*.conf
One file per pool, for example, a pool named "mike" -
/opt/php53/etc/fpm.d/pools/mike.conf:
[mike] listen = 127.0.0.1:11000 user = mike group = mike request_slowlog_timeout = 5s slowlog = /opt/php53/var/log/slowlog-mike.log pm.max_children = 5 pm.start_servers = 3 pm.min_spare_servers = 2 pm.max_spare_servers = 4 pm.max_requests = 500 include = /opt/php53/etc/fpm.d/common.conf
Common elements for each pool (if these could be inherited globally, which they MIGHT be, I could just toss them in the main php-fpm.conf. Perhaps a feature request. Will post on the mailing list...)
Remember that rlimit_files
needs to be something set in your sysctl.conf or on the system level or you'll get that RLIMIT_NOFILE warning. Also, depending on how you want to limit resources per pool/client, you may want to tweak things, such as request_terminate_timeout
.
/opt/php53/etc/fpm.d/common.conf:
listen.backlog = -1 listen.allowed_clients = 127.0.0.1 pm = dynamic pm.status_path = /status ping.path = /ping ping.response = pong request_terminate_timeout = 120s rlimit_files = 131072 rlimit_core = unlimited catch_workers_output = yes env[HOSTNAME] = $HOSTNAME env[PATH] = /bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/opt/php53/bin:/opt/php53/sbin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
As always, YMMV.