Your PHP site feel fine all week. Then suddenly newsletter goes out, product get shared, or sale starts, and page that normally load in under second start hanging. To Configure PHP-FPM effectively and improve application performance, you first need to understand what’s happening behind the scenes. You open the PHP-FPM log and find one line repeated over and over:
WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
This warning is one of most common PHP-FPM log line on busy server, and in my experience “consider raising it” is start of investigation, not fix. If you configure PHP-FPM by guessing, you can turn slow site into crashing one. Raise worker limit too far and server run out of memory. Leave it too low and request wait in line while CPU sits idle.
In this blog, I will show how request reaches a PHP worker, calculate “pm.max_children” from measured memory, apply changes safely.
TL;DR
- PHP-FPM performance depends on properly configured worker processes, available server memory, CPU capacity, and application workload.
- Choose the right PHP-FPM process manager (dynamic, ondemand, or static) based on your website’s traffic patterns and resource requirements.
- Calculate “pm.max_children” using the measured memory usage (PSS) of busy PHP-FPM workers instead of guessing.
- Monitor PHP-FPM status, request queues, slow logs, CPU, RAM, swap, and database load to identify performance bottlenecks.
- Optimize slow database queries, external API calls, and application code before increasing PHP-FPM worker limits.
- Apply PHP-FPM configuration changes safely by backing up files, testing configurations, and performing graceful reloads.
What PHP-FPM does and where to look for bottlenecks
Before you change single setting, you want clear picture of where request spend its time.
How request travel from Apache to PHP worker: Apache use PHP-FPM, it doesn’t run PHP itself. Apache serve static files directly, and when request hits a “.php” file, “mod_proxy_fcgi” module pass it over FastCGI protocol to PHP-FPM, usually through Unix socket such as “/run/php/php8.3-fpm.sock”. On Ubuntu, that handoff is set in “/etc/apache2/conf-available/php8.3-fpm.conf” with line like:
SetHandler "<code>proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost</code>"
This is different from the older “mod_php” setup, where PHP run inside every Apache process. PHP-FPM keep PHP in its own pool of worker, which lets Apache use the lighter “event” MPM and lets you size PHP separately.
PHP-FPM manage one or more pools. Each pool is group of worker process, and each worker handle exactly one request at a time.
So when people say “PHP is slow,” request might be slow inside PHP, or it might be sitting in line waiting for free worker. Those are two very different problems.
Read Full Article: https://serveravatar.com/configure-php-fpm

Top comments (0)