Help Center

Why does my website exhaust PHP max_children?

What is max_children and what does it do?

The variable max_children of 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?

  1. If the site’s scripts cannot respond to existing requests before new requests arrive, PHP-FPM will spawn additional PHP processes to handle them in parallel.
  2. PHP-FPM will continue spawning more additional PHP processes as requests pile up on the site.
  3. However, once the number of processes reaches the limit set by max_children, PHP-FPM will stop spawning additional PHP processes.
  4. At that point, additional requests will be placed in a waiting queue and will only be responded to once an existing request completes.

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 that run at the same time.

Since website visitors usually make requests every few seconds and PHP execution time is only a small part 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 operation:

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 execute immediately, and the next 5 that arrive will be put on hold until the previous requests complete. Each resolved request will free up a slot for a waiting request, and so on until all are finished.

The number of visitors to your website will most likely be greater than the max_children limit, but due to the time intervals between visitors’ actions and the relatively short execution time of PHP scripts, the website can still respond to all requests efficiently.

Therefore, with a max_children of 10, your website will be able to support up to 10,000 visitors at the same time.

You can see how important fast execution of PHP scripts is.
If each PHP request took 2 seconds to execute, instead of 10 milliseconds, the website could only support 100 visitors at the same time.

Reaching the max_children limit indicates that some part of the website is running an excessively slow PHP process.

Guide g.0208 · Source version 1 · en