Two process management modes of PHP-FPM

Source: Internet
Author: User
Tags vps

Two process management modes of PHP-FPM

The number of PHP-FPM processes can also be divided into dynamic and static Based on the settings.
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.Php5.3

The default static Processing Method of PHP-FPM makes the PHP-CGI process occupy memory for a long time and cannot be released. This is also the cause of nginx errors, therefore, you can change the PHP-FPM Processing Method to the Apache mode.


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 specific maximum quantity depends 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.

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.