PHP-FPM Optimization Method Detailed

Source: Internet
Author: User
Tags vps

PHP-FPM Optimization method

PHP-FPM exists in two ways, one is to directly open the specified number of PHP-FPM processes, no longer increase or decrease;
The other is to start with a certain number of php-fpm processes, when the request is large, dynamically increase the number of PHP-FPM processes to the upper limit, when idle free process to automatically release the number to a lower limit.
These two different execution modes can be adjusted according to the actual needs of the server.

Some of the parameters to use are PM, Pm.max_children, Pm.start_servers, Pm.min_spare_servers, and Pm.max_spare_servers.

PM means that there are two values that can be selected, either static or dynamic, in that way.

The meanings of the following 4 parameters are:

Pm.max_children: The number of PHP-FPM processes opened in static mode, in dynamic mode he limits the maximum number of processes PHP-FPM (note that the value of pm.max_spare_servers is only less than or equal to Pm.max_children)
Pm.start_servers: The number of start PHP-FPM processes under dynamic mode.
Pm.min_spare_servers: The minimum number of PHP-FPM processes in the dynamic idle state.
Pm.max_spare_servers: The maximum number of php-fpm processes in the dynamic idle state.

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

If the DM is set to dynamic,4, all parameters are in effect. The system starts the Pm.start_servers PHP-FPM process at the start of the PHP-FPM run and then dynamically pm.min_spare_servers and Pm.max_spare_ according to the system's requirements Adjusts the number of PHP-FPM processes between servers.

So, for the server, which method of execution is better to choose? In fact, like Apache, the running PHP program will have more or less memory leaks after the execution is completed. This is why the beginning of a PHP-FPM process only takes up about 3M of memory, running for a period of time will rise to 20-30m reason. (www. Scripting Academy)

Therefore, the dynamic mode because it will end the redundant process, can be reclaimed to release some memory, so it is recommended to use on the server or VPS with less memory. The specific maximum number is based on the memory/20m.
For example, 512M VPS, recommended pm.max_spare_servers set to 20 (512*0.8/20). As for Pm.min_spare_servers, it is recommended to set the load on the server and compare the appropriate values between 5~10.

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

For example, if it is a 512M VPS, set the parameters as follows:

code example: pm=dynamic
Pm.max_children=20
Pm.start_servers=5
Pm.min_spare_servers=5
Pm.max_spare_servers=20

It can save memory and improve execution efficiency.

PHP-FPM Optimization Method Detailed

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.