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.