What Is PHP-FPM?


#1

What Is PHP-FPM?

PHP-FPM (FastCGI Process Manager) is a PHP implementation of FastCGI that works a bit differently than other PHP implementations. The primary difference is that PHP-FPM is actually not dependent on the Apache web server but instead works more independently of the web server. The PHP-FPM implementation is actually is own server instance that is stand-alone from Apache. When a PHP process is recognized it is sent to the PHP-FPM pool (PHP-FPM server) to process. This has the unique advantage of offloading workload from Apache to an instance that will handle the PHP processes and then respond to the browser with the result.

PHP-FPM Management Methods

There are a few methods for configuring PHP-FPM, most default installation guides will encourage the use of “dynamic” management, which is perfectly fine it is own right but there are other methods like “static” or “ondemand” which can provide benefits depending on the need. The available Process Management options are listed below:

  • Dynamic
  • Static
  • Ondemand

Dynamic Process Management

For a Flexible control over the PHP pool threshold, utilizing “dynamic” pool management can be an easier way to manage the PHP pool threshold as it will start and stop pools based on need. In so much that you can configure an upper and lower limit and allow the requests to determine the usage. Additionally, the dynamic method is dependent on a start server configuration that will automatically spin up a number of pools on process start. Using Dynamic process management the utilization of the PHP pools will be best determined by the following directives in the PHP-FPM configuration.

  • pm.max_children - The maximum number of child processes (pools).
  • pm.start_servers -The amounts of pools that are initiated on process start.
  • pm.min_spare_servers -The desired minimum amount of idle pools.
  • pm.max_spare_servers -The desired maximum amount of idle pools.
  • pm.max_request - The maximum number of requests before child process respawn (Not required for dynamic management, but I highly recommend it. It can help alleviate resource exhaustion or at least delay it long enough to be addressed.)

Static Process Management

For strict control over the PHP pool threshold, regardless of traffic volume, You can choose to implement a static process management which will set a fixed amount of children and process PHP based on a fixed number of requests. This will force the PHP processes to be killed and respawn spinning up a new pool if the pool becomes overworked. While less graceful, it is the simplest method of configuration and requires less input from the system administrator. Using Static process management the utilization of the PHP pools will be best determined by the following directives in the PHP-FPM configuration.

  • pm.max_children - The maximum number of child processes (pools).
  • pm.max_request - The maximum number of requests before child process respawn (Not required for static management, but I highly recommend it. It can help alleviate resource exhaustion or at least delay it long enough to be addressed.)

Ondemand Process Management

The most flexible option of process management, ondemand will function in the exact manner of its namesake, on demand. This process management is similar in implementation as dynamic, but without the idle process control as will be no idle process. Ondemend process management will kill any unused pool. I would recommend this option only for low traffic sites that may have some more intensive PHP processes that need to be completed. The process management method is not recommended for high traffic sites or sites that need a high level of php performance. Using Ondemand process management the utilization of the PHP pools will be best determined by the following directives in the PHP-FPM configuration.

  • pm.max_idle_timeout - The Maximum amount of time for a pool to exist while waiting for a process. Once this timeout limit is reached the process will be killed.
  • pm.max_children - The Maximum number of child processes (pools).
  • pm.max_request - The maximum number of requests before child process respawn (Not required for ondemand management, but I highly recommend it. It can help alleviate resource exhaustion or at least delay it long enough to be addressed.)

For more information on PHP-FPM configuration directives please see the following link:

PHP-FPM Management In cPanel

For the most part, PHP-FPM management in the cPanel system is self-contained and requires little input from the system’s administrator other than to enable it and to decide for which users the pools can be created.

I do highly recommend to enable it for the cPanel System to optimize the cPanel itself.

To enable System PHP-FPM for your server, please follow the steps listed below:

  1. Log into your WHM interface.

    WHM_Login

  2. Navigate to the 'Multi-PHP manager’

    MultiPHP_Manager

  3. If the system is ready to enable PHP-FPM, you will see the option to ‘turn-on’ the system PHP-FPM is available. If not you will need to install the required dependencies.

    Note: You will see that there is an option to install the necessary dependencies directly above the warning. Click the ‘Install’ to provision PHP-FPM for the Easy Apache instance, which allows Apache to utilize the PHP-FPM implementation.