This resource provides information about tuning the Max Children limit for PHP FPM.
If you would prefer not to tune PHP-FPM's Max Children limit, you may consider switching to the LSAPI handler:
How to switch from PHP-FPM to the LSAPI handler
The max_children directive defines the maximum number of PHP-FPM processes allowed to spawn. In the cPanel context, max_children is applied on a per-domain basis. A max_children setting of 5 means only five processes can spawn for that particular domain.
The purpose of the max_children directive is to provide a way to limit the number of resources used by PHP-FPM so that it cannot overwhelm the server. When the limit is hit, only a single domain will become unavailable. Without the limit, traffic from a single domain could crash the entire server in certain circumstances.
Adjusting Max Children via WHM
The most straightforward approach to adjusting max_children is to increase the value by increments of 5 when the domain hits the limit. While doing this, you should pay close attention to the server's overall CPU, memory, and IO resource usage.
- Login to WHM as the root user
- Navigate to: "Home / Software / MultiPHP Manager"
- Click on the "User Domain Settings" tab
- In the table, click on the "PHP-FPM Settings" button at the far right of your domain's row
- Update the "Max Children" value to your desired value
- Click the blue "Update" button at the bottom of the page
Checking the PHP-FPM Logs for Max Children Limit Hits
- Access your server as the root user via Terminal or SSH
- Run the following command to find the FPM logs:
find /opt/cpanel/ea-php*/root/usr/var/log/php-fpm/ -type f -name error.log
- Run the following command on the log corresponding to the version of PHP your domain is using. PHP 8 is used in this example:
grep max_children /opt/cpanel/ea-php80/root/usr/var/log/php-fpm/error.log
A Domain is Constantly Hitting Max Children
If your domain constantly hits the max_children limit when you raise the value and your server runs out of resources, you should check to see if the server is experiencing a DoS attack.
How can I tell if Apache is experiencing a DDoS attack?
If you confirm that the traffic is legitimate and is not due to a DoS attack, you may consider a few options:
- Migrate the site to a different server with more resources
- Upgrade the resources of the existing server
- Consult with a systems administrator to optimize the site so that it uses less resources
Apache Max Request Workers in Relation to Max Children
Apache's Max Request Workers configuration is a very similar concept to Max Children for PHP-FPM.
For each request that comes in, Apache will assign a worker to that request. The Apache workers then send the request to a PHP-FPM child process.
If the combined total of the max_children values for all domains on the server is larger than the Apache Max Request Workers value, the Max Request Workers configuration can create a bottleneck. You may need to adjust Apache's Max Request workers after adjusting PHP-FPM's max_children.
A detailed explanation of the Max Request Workers configuration for Apache is out of the scope of this guide, but another more in-depth guide can be found here:
Tuning MaxRequestWorkers for Apache