Simple analysis on the comparison _php skill of php-fpm static and dynamic execution mode

Source: Internet
Author: User
Tags fpm php programming vps

This article illustrates the comparison of php-fpm static and dynamic execution methods. Share to everyone for your reference, specific as follows:

Before the time to configure PHP-FPM, inadvertently found that he still has two ways of implementation. Like Apache, his number of processes can be divided into dynamic and static according to the settings.

And PHP-FPM also exist in two ways , One is to open a specified number of PHP-FPM process, no longer increase or decrease; the other is to open a certain number of php-fpm processes at the beginning, when the request is large, Dynamically increase the number of PHP-FPM processes to the upper limit and automatically release idle processes to a lower limit when idle.

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

Here are some of the parameters involved in this, they are pm, Pm.max_children, Pm.start_servers, Pm.min_spare_servers and Pm.max_spare_servers.

PM indicates that in that way, there are two values that can be selected, either static (static) or dynamic. in older versions, dynamic is called Apache-like. This should be paid attention to the description given by the configuration file.

The following 4 parameters mean:

Pm.max_children: The number of PHP-FPM processes that are open 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 under dynamic mode.
Pm.max_spare_servers: The maximum number of PHP-FPM processes under dynamic mode.

If the DM is set to static, then only pm.max_children this parameter is in effect. The system will open the set number of PHP-FPM processes.

If the DM is set to dynamic, then the Pm.max_children parameter fails and the following 3 parameters take effect. The system starts the Pm.start_servers PHP-FPM process at the start of the PHP-FPM operation, and then dynamically pm.min_spare_servers and pm.max_spare_ according to the requirements of the system Adjusts the number of PHP-FPM processes between servers.

So, what's the best way to do this for our servers? In fact, like Apache, we run a PHP program that, after execution, is more or less a problem with memory leaks. This is why the beginning of a PHP-FPM process consumes only about 3M of memory, running for a period of time will rise to 20-30m reasons. Therefore, the dynamic way because it will end the redundant process, you can reclaim some memory, so it is recommended in less memory servers or VPS to use. The specific maximum quantity is obtained according to the memory/20m. For example, 512M VPS, recommended pm.max_spare_servers set to 20. As for Pm.min_spare_servers, it is recommended to set the server's load, the appropriate value between 5~10.

Then, for servers with larger memory, it is more efficient to set them to static. Because the frequent switch php-fpm process will sometimes lag, so the memory is large enough to open the static effect will be better. Quantity can also be obtained according to memory/30m. For example, 2GB memory server can be set to 50;4GB memory can be set to 100 and so on.

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

Pm=dynamic
Pm.max_children=20
Pm.start_servers=5
Pm.min_spare_servers=5
Pm.max_spare_servers=20

This allows for maximum memory savings and increased execution efficiency.

With the parameter description:

PM string Sets how the Process manager manages child processes. Available values: Static,ondemand,dynamic. Must be set.
Static The number of child processes is fixed (pm.max_children).
OnDemand A process is generated when there is a demand (when requested, the Pm.start_servers is started when the service starts, as opposed to dynamic.)
Dynamic The number of child processes is set dynamically on the basis of the following configuration: Pm.max_children,pm.start_servers,pm.min_spare_servers,pm.max_spare_servers.
Pm.max_children int PM when set to static indicates the number of child processes created, and the maximum number of child processes that can be created when the PM is set to dynamic. Must be set. This option sets the limit of the number of requests that can provide the service at the same time. Similar to the maxclients settings in Apache mpm_prefork and the Php_fcgi_children environment variables 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 subprocess is reborn. is useful for Third-party modules that may have memory leaks. If set to ' 0 ', the request is always accepted, equivalent to the php_fcgi_max_requests environment variable. Default value: 0.

More about PHP Interested readers can view the site topics: "PHP Design Security Course", "PHP object-oriented Program Design Introductory Course", "PHP Mathematical Calculation Skills Summary", "PHP Array" Operation Techniques Encyclopedia, "PHP string (String) Usage summary, "PHP Data structure and algorithm tutorial", "PHP Programming algorithm Summary" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

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.