Skip to content

Trellis PHP Children & Servers Increase

By Jasper Frumau

As we use Fast CGI Micro Caching on our Roots Trellis server we needed more PHP children, start and spare servers. We had an error loading the site on opening a post for editing. When we checked the logs we saw this

root@ubuntu-4gb-fsn1-1:~# sudo tail -n 50 /var/log/php8.2-fpm.log
[09-Mar-2025 00:00:01] NOTICE: error log file re-opened
[09-Mar-2025 00:09:50] WARNING: [pool wordpress] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 6 total children
[09-Mar-2025 06:11:35] WARNING: [pool wordpress] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 6 total children
...
[10-Mar-2025 02:30:56] WARNING: [pool wordpress] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 7 total children
[10-Mar-2025 02:30:57] WARNING: [pool wordpress] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 8 total children
[10-Mar-2025 02:30:58] WARNING: [pool wordpress] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 9 total children
[10-Mar-2025 02:30:59] WARNING: [pool wordpress] server reached pm.max_children setting (10), consider raising it

So we update trellis/roles/wordpress-setup/defaults/main.yml . We had

# PHP FPM
php_fpm_pm: 'dynamic'
php_fpm_pm_max_children: 10
php_fpm_pm_start_servers: 1
php_fpm_pm_min_spare_servers: 1
php_fpm_pm_max_spare_servers: 3
php_fpm_pm_max_requests: 500

and we moved onto

# PHP FPM
php_fpm_pm: 'dynamic'
php_fpm_pm_max_children: 30
php_fpm_pm_start_servers: 6
php_fpm_pm_min_spare_servers: 4
php_fpm_pm_max_spare_servers: 10
php_fpm_pm_max_requests: 500

Then we ran trellis provision --tags=wordpress-setup,php production . We then ran into a Let’s Encrypt error

TASK [letsencrypt : Generate the certificates] *********************************
fatal: [xxx.xxx.xxx]: FAILED! => {"changed": false, "cmd": ["./renew-certs.py"], "delta": "0:00:00.036810", "end": "2025-03-10 02:56:15.813593", "msg": "non-zero return code", "rc": 1, "start": "2025-03-10 02:56:15.776783", "stderr": "The required CSR file /var/lib/letsencrypt/csrs/imagewize.com-091c0c8.csr does not exist. This could happen if you changed site_hosts and have not yet rerun the letsencrypt role. Create the CSR file by re-provisioning (running the Trellis server.yml playbook) with `--tags letsencrypt`", "stderr_lines": ["The required CSR file /var/lib/letsencrypt/csrs/site.com-091c0c8.csr does not exist. This could happen if you changed site_hosts and have not yet rerun the letsencrypt role. Create the CSR file by re-provisioning (running the Trellis server.yml playbook) with `--tags letsencrypt`"], "stdout": "", "stdout_lines": []}

so we also ran trellis provision --tags=letsencrypt production . Once that was all done the site was running again. And just to be sure we checked on the server if all was added:

cat /etc/php/8.2/fpm/pool.d/wordpress.conf
; Ansible managed

[wordpress]
listen = /var/run/php-fpm-wordpress.sock
listen.owner = www-data
listen.group = www-data
user = web
group = www-data
pm = dynamic
pm.max_children = 30
pm.start_servers = 6
pm.min_spare_servers = 4
pm.max_spare_servers = 10
pm.max_requests = 500
chdir = /srv/www/
php_flag[log_errors] = on
php_flag[display_errors] = Off
php_admin_value[open_basedir] = /srv/www/:/tmp

All there. And when we checked for current PHP FPM children processes running we saw

ps aux | grep php-fpm | grep -v grep | wc -l
11

so 11 or one more than we allowed for. And enough room now for adding more if more is required. When I watched for memory usage by PHP Children :

watch -n 2 'ps -eo rss,pid,user,args | grep "[p]hp-fpm: pool wordpress" | awk "{sum+=\$1} END {print \"Total PHP-FPM Memory: \" sum/1024 \" MB\", \"Processes: \" NR}"'

I got results like

Every 2.0s: ps -eo rss,pid,user,args | grep "[p]hp-fpm: pool w...  ubuntu-4gb-fsn1-1: Mon Mar 10 03:34:01 2025

Total PHP-FPM Memory: 2090.34 MB Processes: 16

or more quiet

Every 2.0s: ps -eo rss,pid,user,args | grep "[p]hp-fpm: pool w...  ubuntu-4gb-fsn1-1: Mon Mar 10 03:34:35 2025

Total PHP-FPM Memory: 1393.64 MB Processes: 10

Must say that 2 GB is a lot as it is half. Might have to look at this still some more. Once a post has been micro cached you do not get a spike. But it is only for 30 seconds. So may need to do caching longer.

Leave a Reply