PHP-FPM Configuration: Pools, Workers and Performance Tuning

PHP · 19.04.2026
PHP-FPM Configuration: Pools, Workers and Performance Tuning

What is PHP-FPM and Why Configure It

PHP-FPM (FastCGI Process Manager) runs PHP as a separate service. Paired with Nginx, it delivers high performance: Nginx handles static files while PHP-FPM handles dynamic requests. Proper PHP-FPM tuning can serve 2–5x more requests without adding RAM.

Pool Configuration File

sudo nano /etc/php/8.2/fpm/pool.d/www.conf

Process Manager Modes

ModeDescriptionWhen to Use
staticFixed number of processesHigh-traffic servers with enough RAM
dynamicProcess count adjusts dynamicallyMost VPS (recommended)
ondemandProcesses created on demandLow-traffic, RAM conservation

Optimal pm Settings for dynamic Mode

pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 8
pm.max_requests = 500
Formula for pm.max_children: Divide available RAM by average PHP process size. Example: 2 GB RAM, 80 MB per process → max_children = 25. Check average size: ps -o rss= -C php-fpm8.2 | awk '{ sum+=$1 } END { print sum/NR/1024 " MB" }'

Slow Log

slowlog = /var/log/php8.2-fpm-slow.log
request_slowlog_timeout = 5s

Apply Configuration

sudo systemctl reload php8.2-fpm
Use reload instead of restart to avoid dropping active connections.
← Back to Knowledge Base Ask Support