PHP-FPM pm.max_children Explained: Configuration, Performance, and Best Practices

Published: 2026-07-12

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

Operating System : AlmaLinux 10
PHP Version      : PHP 8.3
Web Server       : Nginx
PHP-FPM          : Enabled
Architecture     : x86_64
Last Tested      : July 2026

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:

pm = dynamic
pm.max_children = 20

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

          Client Requests
                 โ”‚
                 โ–ผ
             PHP-FPM Pool
                 โ”‚
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚               โ”‚               โ”‚
 โ–ผ               โ–ผ               โ–ผ
Worker 1      Worker 2      Worker 3
 Busy          Busy          Idle

When all workers are busy:

Client Request
      โ”‚
      โ–ผ
Waiting Queue
      โ”‚
      โ–ผ
Next Available Worker

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:

pm.max_children =
Available RAM
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Average Memory per PHP Worker

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:

ps --no-headers -o rss -C php-fpm

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.

| Directive            | Purpose                                           |
| -------------------- | ------------------------------------------------- |
| `pm.max_children`    | Maximum number of concurrent PHP worker processes |
| `max_execution_time` | Maximum execution time of a single PHP script     |

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.

PHP-FPM Pool
      โ”‚
      โ”œโ”€โ”€ pm
      โ”œโ”€โ”€ pm.max_children
      โ”œโ”€โ”€ pm.start_servers
      โ”œโ”€โ”€ pm.min_spare_servers
      โ”œโ”€โ”€ pm.max_spare_servers
      โ””โ”€โ”€ pm.max_requests

Proper tuning requires considering these settings as a whole rather than changing only one value.

Recommended Values

| Server Memory | Typical Starting Point |
| ------------- | ---------------------- |
|          1 GB |                   5โ€“10 |
|          2 GB |                  10โ€“20 |
|          4 GB |                  30โ€“50 |
|          8 GB |                 60โ€“100 |
|         16 GB |                120โ€“200 |

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

Technology Guides โ†’

โ€บ 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

Southeast Asia Insights โ†’

โ€บ 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