[Highlights] PHP-FPM Configuration Optimization

Source: Internet
Author: User
【】Php-fpmconfiguration optimization www.linuxidc.comlinux2011-0535346.htm ??? Request_terminate_timeout30 # indicates that after 30 seconds, php scripts that are not automatically ended are ended to release the occupied resources .? Max_execution_time in php. ini [summary] PHP-FPM Configuration Optimization

Http://www.linuxidc.com/Linux/2011-05/35346.htm

?

?

?

Request_terminate_timeout = 30
# It indicates that after 30 seconds, the php scripts that are not automatically ended are ended to release the occupied resources.

?

Max_execution_time in php. iniAlso need to be adjusted

?

?

?


The following parameters are involved: 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. Note the configuration file description.

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 the pm. start_servers php-fpm processes at the beginning of the php-fpm operation,
Then, adjust the number of php-fpm processes between pm. min_spare_servers and pm. max_spare_servers according to system requirements.

Which execution method is better for our servers? In fact, like Apache, the running PHP program may have more or less memory leakage 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.

For servers with a large memory (such as 8 GB or above), it is more appropriate to specify the static max_children, because no additional process count control is required and the efficiency is improved.
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 the memory/30 M, for example, 8 GB memory can be set to 100,
The memory used by the php-fpm can be controlled at 2G-3G. If the memory is slightly smaller, such as 1 GB, the specified number of static processes is more conducive to server stability.
In this way, php-fpm can only obtain enough memory and allocate a small amount of memory to other applications, making the system run more smoothly.

For servers with small memory, for example, VPS with M memory, even if a 20 m memory is used, 10 php-cgi processes will consume m of memory, the collapse of the system should be normal.
Therefore, we should try our best to control the number of php-fpm processes, and specify a small static number for other applications after specifying the memory occupied by other applications, which will make the system more stable. Or use a dynamic method,
Because the excessive process is terminated dynamically and some memory can be recycled and released, we recommend that you use it 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 value based on the server load. the value range is 5 ~ Between 10.

?

?

?

?

?

============================== 127.0.0.1 listens to the local ip address

?

Php-fpm.conf

Listen = 127.0.0.1: 9000

?

?

?

Nginx. conf


? Location ~ ^ (. + \. Php) (. *) $ {
????? Fastcgi_pass ?? 127.0.0.1: 9000;
????? Fastcgi_index? Index. php;
????? Fcinclude GI. conf;
??? }

?

?

?

?

?

?

?

?

?

?

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.