PHP-FPM pm.max_children Explained: Configuration, Performance, and Best Practices
Introduction
The pm.max_children directive is one of the most important PHP-FPM configuration options. It defines the maximum number of PHP worker processes that can run simultaneously in a process pool.
Each worker process can handle one request at a time. If all workers are busy, additional requests must wait until a worker becomes available. Choosing an appropriate value is essential for balancing server performance, memory usage, and application responsiveness.
This guide explains how pm.max_children works, how to calculate an appropriate value, common configuration mistakes, and best practices for production environments.
Test Environment
What Is pm.max_children?
Every PHP request is handled by a PHP-FPM worker process.
The pm.max_children directive limits how many worker processes can exist simultaneously.
Example:
With this configuration, PHP-FPM can process up to 20 requests at the same time.
If a twenty-first request arrives while all workers are busy, it waits until a worker becomes available.
How PHP-FPM Handles Requests
When all workers are busy:
If requests continue to arrive faster than workers become available, users may experience slower response times or timeout errors.
Check the Current Value
Locate the PHP-FPM pool configuration.
Common locations include:
/etc/php-fpm.d/www.conf
or
/etc/php/8.x/fpm/pool.d/www.conf
Run:
grep pm.max_children /etc/php-fpm.d/www.conf
Example:
pm.max_children = 20
Change pm.max_children
Open the pool configuration.
sudo nano /etc/php-fpm.d/www.conf
Locate:
pm.max_children = 20
Example:
pm.max_children = 50
Save the file.
Restart PHP-FPM
Apply the changes.
sudo systemctl restart php-fpm
Verify:
sudo systemctl status php-fpm
Expected output:
Active: active (running)
How to Calculate pm.max_children
The correct value depends primarily on available RAM.
A common formula is:
Example:
Server memory available for PHP:
4 GB
Average PHP worker memory usage:
80 MB
Calculation:
4096 รท 80 โ 51
A practical configuration would be:
pm.max_children = 50
Always leave enough memory for:
Linux kernel
Nginx or Apache
MySQL or MariaDB
Redis
System services
Using all available RAM for PHP-FPM may lead to swapping or out-of-memory conditions.
Measure Worker Memory Usage
Instead of guessing, measure the actual memory consumption.
Example:
RSS values are reported in kilobytes.
To calculate the average:
Average RSS ร Number of Workers
Using real production data produces a much more accurate pm.max_children value than relying on generic recommendations.
Common Errors
server reached pm.max_children setting
Example log message:
WARNING: [pool www] server reached pm.max_children setting
This means every worker process is busy.
Possible solutions:
Increase pm.max_children if memory allows.
Optimize slow PHP code.
Reduce database query time.
Enable OPcache.
Add more server memory if necessary.
Simply increasing the limit without investigating slow requests may hide the real bottleneck.
502 Bad Gateway
A 502 error does not always indicate a pm.max_children problem, but an overloaded PHP-FPM pool can contribute to it.
Other possible causes include:
PHP-FPM stopped running.
Socket permission problems.
PHP crashes.
Long-running scripts.
Upstream timeout settings.
Review PHP-FPM and web server logs to identify the root cause.
High Memory Usage
Setting:
pm.max_children = 500
does not automatically improve performance.
If each worker consumes 100 MB:
500 ร 100 MB = 50 GB RAM
On a server with only 8 GB of memory, this configuration would almost certainly cause memory exhaustion.
pm.max_children vs max_execution_time
These settings control different aspects of PHP.
Increasing max_execution_time does not allow PHP-FPM to process more requests simultaneously.
Relationship with Other PHP-FPM Settings
pm.max_children works together with several pool directives.
Proper tuning requires considering these settings as a whole rather than changing only one value.
Recommended Values
These are starting points only. Always calculate the value using actual worker memory usage.
Best Practices
Base pm.max_children on measured memory consumption rather than estimates.
Leave sufficient RAM for the operating system, web server, database, and other services.
Monitor PHP-FPM logs for server reached pm.max_children setting warnings.
Optimize slow PHP code before continuously increasing worker limits.
Review the configuration after application updates or traffic growth.
Conclusion
The pm.max_children directive determines how many PHP-FPM worker processes can handle requests simultaneously. Setting it too low may create request queues and slow response times, while setting it too high can exhaust server memory and reduce overall stability.
The most effective approach is to measure the average memory usage of PHP workers, calculate a value based on available RAM, and monitor the server under real workloads. Combined with proper tuning of related PHP-FPM settings, an appropriate pm.max_children value helps deliver consistent performance and reliable resource utilization.
Explore More
โบ PHP-FPM pm.max_requests Explained: Configuration, Memory Management, and Best Practices
โบ PHP-FPM pm.start_servers Explained: Configuration, Worker Management, and Best Practices
โบ PHP-FPM pm.min_spare_servers Explained: Configuration, Idle Workers, and Best Practices
โบ PHP-FPM pm.max_spare_servers Explained: Configuration, Idle Worker Limits, and Best Practices
โบ Best Areas to Live in Bangkok in 2026: A Complete Guide for Expats and Digital Nomads
โบ Best Coworking Spaces in Bangkok 2026: A Guide for Digital Nomads and Remote Workers
โบ Why Do People in Southeast Asia Love Iced Drinks? The Climate, Culture, and Science Explained
โบ Best eSIM for Southeast Asia in 2026: Compare the Top Travel eSIMs