Detailed _php example of two kinds of process management modes in depth PHP-FPM

Source: Internet
Author: User
Tags fpm vps
Two kinds of process management modes in PHP-FPM
The number of PHP-FPM processes can also be divided according to the settings Dynamic and StaticOf
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 process, when the request is large, dynamic increase in the number of PHP-FPM process to the upper limit, when the idle time automatically free to release the number of processes to a lower limit.
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. PHP5.3
PHP-FPM's default static processing allows php-cgi processes to occupy memory for a long time and cannot be freed, which is one of the causes of Nginx errors, so you can change PHP-FPM processing to Apache mode.
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.

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.