Why does my website exhaust PHP Max Children?
Hashtags: #php #fpm #limits
What is max_children and what does it do?
The max_children variable in PHP is a setting that controls the maximum number of PHP requests that can run at the same time on a website. This limit helps protect the server from scripts that are slow or buggy and could consume all available memory.
What happens when the max_children limit is reached?
- If the website’s scripts cannot respond to existing requests before new requests arrive, PHP-FPM will spawn additional PHP processes to handle them in parallel.
- PHP-FPM will continue spawning more PHP processes as requests pile up on the website.
- However, once the number of processes reaches the limit set by max_children, PHP-FPM will stop spawning additional PHP processes.
- At that point, additional requests will be placed in a waiting queue and will only be served once an existing request finishes.
It is important to note that the max_children variable does not limit the number of simultaneous visitors your site can have, but rather the maximum number of PHP requests running at the same time.
Since website visitors typically make requests every few seconds and PHP execution time is only a small portion of the total time required to complete a request, the number of visitors your website can handle is much higher than the limit set by max_children.
Example of how it works:
Each visitor to your website clicks a link or submits a form every 10 seconds. Each requested PHP script takes 10 milliseconds to execute.
According to that example, the first 10 requests will run immediately, and the next 5 that arrive will be put on hold until the previous requests complete. Each resolved request will free a slot for a waiting request, and so on until all are finished.
The number of visitors to your website will likely be greater than the max_children limit, but due to the intervals between visitors’ actions and the relatively short execution time of PHP scripts, the site can still respond to all requests efficiently.

Therefore, with a max_children of 10, your website could support up to 10,000 simultaneous visitors.
You can see how important fast PHP script execution is.
If each PHP request took 2 seconds to execute instead of 10 milliseconds, the website could only support 100 simultaneous visitors.
Reaching the max_children limit indicates that some part of the website is running a PHP process that is too slow.