The solution to the problem of too many php-fpm processes: first back up the original configuration file; then use vim to open the configuration file; then modify the configuration parameters; and finally restart the server through reboot.
The operating environment of this article: CentOS 7 system, PHP7.1 version, DELL G3 computer
What if there are too many php-fpm processes? manage?
Solve the problem of excessive server memory resource consumption caused by too many php-fpm processes in CentOS 7
What is php-fpm:
php-fpm is the FastCGI process manager, used to control php's memory and processes.
Operating environment:
CentOS 7
Problem check:
First check the total number of php processes:
pstree|grep php-fpm
Echo:
|-php-fpm---20*[php-fpm]
According to the response The displayed information shows that there are 20 php-fpm processes during the query.
You can also list the top 50 processes that consume the most memory through the following command:
ps auxw|head -1;ps auxw|sort -rn -k4|head -50
Solution process:
Let’s modify the configuration below file to optimize php-fpm to reduce memory usage.
My php-fpm configuration file is in the .../server/php/etc/ directory, enter this directory.
Back up the original configuration file first:
cp php-fpm.conf php-fpm.conf.bak
Note: After using vim to open the configuration file, press the Esc key, then enter "/", and then enter "xxx" to search for "xxx" string.
The specific configuration parameters are as follows:
pm.max_children = 100改为:pm.max_children = 25 pm.start_servers = 20改为pm.start_servers = 5 pm.min_spare_servers = 5改为pm.min_spare_servers = 2 pm.max_spare_servers = 35改为pm.max_spare_servers = 10
Restart the server:
reboot
After restarting, you can find that the memory usage is lower than before.
Note:
Explanation of the role of parameters in php-fpm.conf:
pm.max_children: The number of php-fpm processes opened in static mode.
pm.start_servers: The number of starting php-fpm processes in dynamic mode.
pm.min_spare_servers: The minimum number of php-fpm processes in dynamic mode.
pm.max_spare_servers: The maximum number of php-fpm processes in dynamic mode.
When making the above settings, I set the execution mode of php-fpm to dynamic:
pm = dynamic
php-fpm has two execution modes:
One is Static and the other is Dynamic. If set to static, only the pm.max_children parameter will take effect. If set to dynamic, the three parameters pm.start_servers, pm.min_spare_servers and pm.max_spare_servers will take effect. After setting it to dynamic, when php-fpm starts, it will start the corresponding number of processes according to the parameter setting of pm.start_servers. After that, the number of processes of php-fpm will be maintained between the number specified by pm.min_spare_servers and pm.max_spare_servers.
How to choose to use the static or dynamic execution mode of php-fpm:
The dynamic php-fpm execution mode allows php-fpm to release redundant processes, thus saving memory resources.
The static php-fpm execution method does not allow php-fpm to release more than processes, which avoids frequently starting or stopping the php-fpm process, thereby reducing the server's response time in some cases.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if there are too many php-fpm processes. For more information, please follow other related articles on the PHP Chinese website!