How to set the number of FPM threads in PHP5.4 on Linux, php5.4fpm
This article describes how to set the number of FPM threads in PHP5.4 on Linux. We will share this with you for your reference. The details are as follows:
After PHP5.4 is installed, the default configuration file for FPM is located in/usr/local/php/etc/php-fpm.conf.default
>cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf>vim /usr/local/php/etc/php-fpm.conf
Enter "/www" to search for the POOL where www is located
pm = dynamic; The number of child processes to be created when pm is set to 'static' and the; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.; This value sets the limit on the number of simultaneous requests that will be; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP; CGI. The below defaults are based on a server without much resources. Don't; forget to tweak pm.* to fit your needs.; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'; Note: This value is mandatory.pm.max_children = 5; The number of child processes created on startup.; Note: Used only when pm is set to 'dynamic'; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2pm.start_servers = 2; The desired minimum number of idle server processes.; Note: Used only when pm is set to 'dynamic'; Note: Mandatory when pm is set to 'dynamic'pm.min_spare_servers = 1; The desired maximum number of idle server processes.; Note: Used only when pm is set to 'dynamic'; Note: Mandatory when pm is set to 'dynamic'pm.max_spare_servers = 3; The number of seconds after which an idle process will be killed.; Note: Used only when pm is set to 'ondemand'; Default Value: 10s;pm.process_idle_timeout = 10s;; The number of requests each child process should execute before respawning.; This can be useful to work around memory leaks in 3rd party libraries. For; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.; Default Value: 0;pm.max_requests = 500
Explanations:
Pm = dynamic: How to Control Sub-processes. The options are static and dynamic. dynamic is used by default. If static is selected, a fixed number of sub-processes is specified by pm. max_children.
If dynamic is selected, it is determined by the following parameters:
| Pm. max_children |
Maximum number of child Processes |
| Pm. start_servers |
Number of processes at startup |
| Pm. min_spare_servers |
The minimum number of idle processes is guaranteed. If the number of idle processes is smaller than this value, a new sub-process is created. |
| Pm. max_spare_servers |
Ensure the maximum number of idle processes. If the number of idle processes is greater than this value, clean up. For dedicated servers, you can set pm to static. |
| Pm. max_requests |
Sets the number of service requests before each sub-process is reborn. it is very useful for third-party modules that may have memory leaks. if it is set to '0', the request is always accepted. set it to 500 (0 by default ). |
Change the value to the following:
pm.max_children = 32pm.start_servers = 16pm.min_spare_servers = 8pm.max_spare_servers = 32pm.max_requests = 500
: Wq save and exit VIM
>/usr/local/php/sbin/php-fpm -tNOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
Test whether the configuration file is normal. No problem. Kill the current FPM process.
>/usr/local/php/sbin/php-fpm
Start