Comparison of static and dynamic execution modes of php-fpm

Source: Internet
Author: User
: This article mainly introduces the comparison of static and dynamic execution methods of php-fpm. For more information about PHP tutorials, see. More please stamp: http://www.webyang.net/Html/web/article_242.html

Some time ago, when I configured php-fpm, I accidentally found that there were two ways to execute it. Like Apache, the number of processes can be divided into dynamic and static based on the settings.


Php-fpm also has two methods. one is to directly enable a specified number of php-fpm processes without increasing or decreasing them; the other is to start a certain number of php-fpm processes at the beginning. when the request volume increases, the php-fpm process is dynamically increased to the upper limit, when idle, idle processes are automatically released to a lower limit.
These two different execution methods can be adjusted according to the actual needs of the server.
Here we will talk about several parameters involved. they are pm, pm. max_children, pm. start_servers, pm. min_spare_servers, and pm. max_spare_servers.
Pm indicates the method used. you can select either static or dynamic values ). In older versions, dynamic is called apache-like. Please note that the configuration file provides instructions.
The meanings of the following four parameters are:
Pm. max_children: Number of php-fpm processes enabled in static mode.
Pm. start_servers: number of initial php-fpm processes in Dynamic mode.
Pm. min_spare_servers: the minimum number of php-fpm processes in Dynamic mode.
Pm. max_spare_servers: maximum number of php-fpm processes in Dynamic mode.
If dm is set to static, only the pm. max_children parameter takes effect. The system will enable the set number of php-fpm processes.
If dm is set to dynamic, the pm. max_children parameter is invalid and the following three parameters take effect. The system starts pm when php-fpm starts running. start_servers php-fpm processes, and then dynamic in pm according to system requirements. min_spare_servers and pm. adjust the number of php-fpm processes between max_spare_servers.
Which execution method is better for our servers? As a matter of fact, like Apache, the PHP program we run has more or less memory leakage problems after execution. This is why a php-fpm process only occupies about 3 m of memory at the beginning, and will rise to 20-30 m after running for a period of time. Therefore, the dynamic mode stops redundant processes and can recycle and release some memory. Therefore, we recommend that you use the dynamic mode on servers or VPS with less memory. The maximum number is calculated based on memory/20 MB. For example, we recommend that you set pm. max_spare_servers to 20 for m vps. For pm. min_spare_servers, we recommend that you set the parameter based on the server load. the value range is 5 ~ Between 10.
Then, for servers with relatively large memory, setting it to static will increase the efficiency. Because frequent switching of the php-fpm process also has a time delay, enabling static mode will be better if the memory is large enough. The quantity can also be obtained based on memory/30 MB. For example, a server with 2 GB memory can be set to 50, and a server with 4 GB memory can be set to 100.
This site is built on m 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 maximum memory saving and execution efficiency can be improved.
Parameters:
Pm string
Sets how the process manager manages sub-processes. Available values: static, ondemand, and dynamic. Required.
Static-the number of sub-processes is fixed (pm. max_children ).
Ondemand-a process is generated only when needed. (when a request is sent, the pm. start_servers starts when the service is started.
The number of dynamic-sub-processes is dynamically set based on the following configuration: pm. max_children, pm. start_servers, pm. min_spare_servers, pm. max_spare_servers.
Pm. max_children int
When pm is set to static, it indicates the number of created sub-processes, and when pm is set to dynamic, it indicates the maximum number of sub-processes that can be created. Required.
This option sets the number of requests that can provide services at the same time. Similar to the setting of MaxClients in Apache mpm_prefork and the PHP_FCGI_CHILDREN environment variable in common PHP FastCGI.
Pm. start_serversin
Set the number of child processes created at startup. It is only used when pm is set to dynamic. Default value: min_spare_servers + (max_spare_servers-min_spare_servers)/2.
Pm. min_spare_servers int
Set the minimum number of idle service processes. It is only used when pm is set to dynamic. Required.
Pm. max_spare_servers int
Set the maximum number of idle service processes. It is only used when pm is set to dynamic. Required.
Pm. max_requests int
Set 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, which is equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value: 0.

The above describes the comparison of php-fpm's static and dynamic execution methods, including some content, and hopes to help those who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.