PHP-FPM Performance Tuning Basics

This resource provides instructions on how to tune performance directives when PHP-FPM is installed and enabled as a PHP handler in cPanel & WHM. Background information on how PHP-FPM is implemented with cPanel & WHM is available on our PHP-FPM documentation.

This document provides valuable information about the main PHP-FPM pool directives, Max Children, Max Requests, and Process Idle Timeout, as well as additional configuration values.

Max Children

Let us start with the most conflicting one which is Max Children it defines the number of PHP-FPM processes to spawn to actually serve requests coming from the web server to process the PHP code.

There isn’t a standardized way to actually determine the Max Children directive as it depends on numerous factors, such as the site’s particular PHP code, however, there is a nice formula to help us be on the safe side:

The above is saying, if we increase Max Children to 100 we can expect each independent PHP process to use 2.62MB of RAM, keep in mind this is per domain per PHP process.

The catch is we need to pre-select a number of Max Children to use in the formula, and then confirm is not going to consume all of the free RAM, in this case, I picked 100 Max Children as an example.

Apache Max Request Workers in relation with PHP-FPM pools

We are not going to cover in detail in this post what Max Request Workers is but we need to mention it because it does not matter how well tuned PHP-FPM's Max Children is configured if Apache is not able to serve those requests coming from it.

Just as PHP-FPM's Max Client setting, Apache's Max Request Workers determines how many requests are going to be accepted. The default configuration setting is 150, which is usually enough for most environments.

According to php.net, this is only useful to avoid memory leaks from 3rd party applications (custom libraries PHP code) which could misbehave and cause memory problems.

For example, you notice a specific site under cPanel account ‘X’ it is consuming excessive amounts of RAM, Max Request will clear out the ram used by the process and start a new one. However, if the problem is constant RAM usage, it will increase again.

Unless you suspect you have an application having memory issues and you suspect is leaking memory, the default value should be fine.

Process Idle Timeout

It defines the number of seconds after which an idle process (process not serving any requests) is set to be killed so it releases CPU time and RAM. The default cPanel value for this is 5 seconds:

Which means the processes are started when they are requested, is not a fixed set of starting processes.

It is important to understand this does not affect PHP’s max_execution_time which is actually going to stop a running process should the threshold be exceeded.

So how does process_idle_timeout affect your performance? It depends, if you are getting constant requests (hot traffic sites) then you want to extend this number in increments of 10 seconds and monitoring between increments.

If you do not have any high traffic sites, then a shorter time will help you free those resources to be used elsewhere.

So, how do you modify these directives? Easy enough, just go to WHM Home »Software »MultiPHP Manager and look for the PHP-FPM column and click the "Pool Options" button which is going to pop out a configuration box.