An Introduction to PHP-FPM Process Manager Modes
Preface
While a server is running, issues such as PHP-FPM consuming too much memory or spawning too many processes can cause the website or the server itself to become unresponsive. So what does the PHP-FPM process manager actually look like? Let’s take a brief look.
Introduction
By inspecting the configuration file, we can see that PHP-FPM has three management modes: { static | dynamic | ondemand}
1 | vim /etc/php/7.0/fpm/pool.d/www.conf |
1 | ; Choose how the process manager will control the number of child processes. |
Details
Static
pm = static
Creates and always maintains a fixed number of child processes at startup.
1 | pm.max_children # limits the maximum number of php-fpm processes |
Dynamic
pm = dynamic (default)
At startup, a fixed number (start_servers) of child processes are created. During operation, new child processes may be created, but the total will not exceed max_children. The number of child processes fluctuates between start_servers and max_children, while the number of idle child processes is controlled by min_spare_servers and max_spare_servers.
1 | pm.max_children # limits the maximum number of php-fpm processes |
Ondemand
pm = ondemand
No child processes are created at startup. Processes are created on demand when requests arrive, and the number will not exceed max_children. A process is released once it has been idle for longer than process_idle_timeout.
1 | pm.max_children # limits the maximum number of php-fpm processes |
Recommendations
- During configuration, you can set
max_childrenusing the formulamemory / 30M(where 30M is the maximum memory used by a single process). staticis suitable for servers with plenty of memory, since creating and releasing child processes consumes server resources (time, memory, CPU…).dynamicis suitable for servers with limited memory; it is flexible and saves memory.ondemandis not recommended for high-traffic applications, as the overhead of constantly creating and releasing a large number of processes is significant.- For production environments, the
staticmode is recommended.