Php-fpm Optimization

Source: Internet
Author: User
The configuration file name involved in this article is php-fpm.conf, which has the following important configuration items. Request_terminate_timeout30 # indicates that after 30 seconds, php scripts that are not automatically ended are ended to release the occupied resources. Pm indicates the method used, that is, static (static) or dynamic (dynamic ). In older versions

The configuration file name involved in this article is php-fpm.conf, which has the following important configuration items. Request_terminate_timeout = 30 # indicates that after 30 seconds, php scripts that are not automatically ended are ended to release the occupied resources. Pm indicates the method used, that is, static (static) or dynamic (dynamic ). In older versions

The configuration file name involved in this article is php-fpm.conf, which has the following important configuration items.

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.

Pm indicates the method used, that is, static (static) or dynamic (dynamic ). In older versions, dynamic is called apache-like.

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? 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 a server with a large memory (such as 8 GB or above), it is more appropriate to specify a 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 memory/30 M. For example, if the 8 GB memory can be set to 100, the memory consumed 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 system crash 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 the dynamic mode, because the dynamic mode will end unnecessary processes and some memory can be recycled and released, it is recommended to use 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 parameter based on the server load. The value range is 5 ~ Between 10.

Original article address: php-fpm optimization. Thank you for sharing it with me.

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.