Php-fpm.conf two crucial parameters

Source: Internet
Author: User
Http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/03/15/1984969.html

 

It specifies the connection, sending, and reading time of the PHP-CGI, 300 seconds is enough, so my server rarely shows 504
Gateway time-out error. The most critical is the php-fpm.conf settings, which directly results in 502 Bad Gateway and 504 gateway time-out.
Next we will carefully analyze several important parameters of the php-fpm.conf:
The php-fpm.conf has two crucial parameters: "max_children" and "request_terminate_timeout"
One of my two values is "40" and the other is "900", but this value is not general, but needs to be calculated by myself.
The calculation method is as follows:
If your server has good performance and sufficient bandwidth resources, you can directly set "request_terminate_timeout" to 0 s if the PHP script does not have loops or bugs. 0 s means to keep the PHP-CGI running without a time limit. And if you can't do that, that is, your PHP-CGI may have a bug, or if your bandwidth is insufficient or your PHP-CGI may be suspended for other reasons, we recommend that you assign a value to "request_terminate_timeout", which can be set based on the performance of your server. In general, the better the performance, the higher you can set, 20 minutes
-30 minutes. Since my server PHP script takes a long time to run, some may take more than 10 minutes, so I set 900 seconds, this will not cause the PHP-CGI to die and the 502 Bad Gateway error occurs.

How is the value of "max_children" calculated? In principle, the larger the value is, the better. If the PHP-CGI process is too large, it will process very quickly and there will be very few requests in the queue. Setting "max_children" also needs to be set based on the server performance. Generally, a server normally consumes about 20 mb of memory per PHP-CGI, so my "max_children" I set to 40, 20 m * 40 = 800m that is to say in the peak of all PHP-CGI consumption within M, less than my Effective Memory 1 GB. If my "max_children" settings are small, such as 5-10, PHP-CGI will be "very tired", the processing speed will be slow, and the waiting time will be long. For example
If a request is not processed for a long time, the error 504 gateway time-out occurs, if the PHP-CGI that is working very well encounters a problem, the 502 Bad Gateway error will occur.

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.