Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between static and dynamic execution in php-fpm

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you what is the difference between static and dynamic execution in php-fpm, I believe most people do not know much about it, so share this article for your reference, I hope you will gain a lot after reading this article, let's go to know it!

The details are as follows:

When configuring php-fpm some time ago, I inadvertently found that he still had two modes of execution. Like Apache, the number of processes can be divided into dynamic and static according to settings.

And php-fpm also has two ways, one is to directly open a specified number of php-fpm processes, no longer increase or decrease; the other is to start a certain number of php-fpm processes, when the number of requests becomes large, dynamically increase the number of php-fpm processes to the upper limit, and automatically release the number of idle processes to a lower limit when idle.

These two different execution methods can be adjusted according to the actual needs of the server.

Let's start with a few parameters related to this. They are pm, pm.max_children, pm.start_servers, pm.min_spare_servers, and pm.max_spare_servers.

Pm means that in that way, there are two values to choose from, namely static (static) or dynamic (dynamic). In older versions, dynamic was called apache-like. This should be noted by the instructions given in the configuration file.

The following four parameters mean:

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.

If dm is set to static, only the parameter pm.max_children takes effect. The system will open the set number of php-fpm processes.

If dm is set to dynamic, then the pm.max_children parameter is invalid and the next three parameters take effect. The system will start pm.start_servers php-fpm processes at the beginning of php-fpm operation, and then dynamically adjust the number of php-fpm processes between pm.min_spare_servers and pm.max_spare_servers according to the needs of the system.

So, which execution method is better for our server? In fact, like Apache, the PHP program we run will more or less have memory leaks after execution. This is why a php-fpm process takes up only about 3 megabytes of memory at the beginning and rises to 20-30 megabytes after a period of time. Therefore, dynamic mode is recommended on servers with less memory or VPS because it will end up redundant processes and can reclaim and release some memory. The specific maximum quantity is obtained according to memory / 20m. For example, for the 512m VPS, it is recommended that the pm.max_spare_servers be set to 20. As for pm.min_spare_servers, it is recommended to set it according to the load of the server, and the more appropriate value is between 5 and 10.

Then for servers with more memory, setting it to static will improve efficiency. Because frequently switching php-fpm processes can sometimes lag, it is better to turn on static when the memory is large enough. The quantity can also be obtained according to memory / 30m. For example, the server with 2GB memory can be set to 50x 4GB memory can be set to 100GB and so on.

This site is built on the 512m VPS, so the parameters I set are as follows:

Pm=dynamic

Pm.max_children=20

Pm.start_servers=5

Pm.min_spare_servers=5

Pm.max_spare_servers=20

In this way, the memory can be saved and the execution efficiency can be improved.

A description of the parameters is attached:

Pm string sets how the process manager manages child processes. Available value: static,ondemand,dynamic. Must be set. The number of staticchild processes is fixed (pm.max_children). The ondemand process is generated when there is a need. (when requested, in contrast to dynamic, pm.start_servers starts when the service starts. The number of dynamic child processes is set dynamically based on the following configuration: pm.max_children,pm.start_servers,pm.min_spare_servers,pm.max_spare_servers. The number of child processes created when pm.max_children intpm is set to static, and the maximum number of child processes that can be created when pm is set to dynamic. Must be set. This option sets the limit on the number of requests that can provide services at the same time. The setting of MaxClients in mpm_prefork similar to Apache and the PHP_FCGI_CHILDREN environment variable in normal PHP FastCGI. Pm.start_serversin sets the number of child processes created at startup. Used only when pm is set to dynamic. Default value: min_spare_servers + (max_spare_servers-min_spare_servers) / 2. Pm.min_spare_servers int sets the minimum number of idle service processes. Used only when pm is set to dynamic. Must be set. Pm.max_spare_servers int sets the maximum number of idle service processes. Used only when pm is set to dynamic. Must be set. Pm.max_requests int sets the number of requests for services before each child process is reborn. It is very useful for third-party modules that may have memory leaks. If set to'0', requests are always accepted, which is equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value: 0. These are all the contents of the article "what's the difference between static and dynamic execution in php-fpm". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report