Yesterday, a program needs to export 500 data, the results found that 150 is, Nginx reported 504 Gateway timeout error
It was observed that time-outs of about 30 seconds were found, and the execution times in php.ini were 300 seconds:
Copy CodeThe code is as follows:
Max_execution_time = 300
Re-check the relevant configuration of nginx, no fruit.
I wrote a test page for PHP and then measured it:
Copy CodeThe code is as follows:
Echo ' AAA ';
Set_time_limit (0);
Sleep (40);
echo ' AA ';
Still timeout, you can determine that the Set_time_limit function is not effective.
Re-check the configuration of php-fcgi php-fpm.conf, below this setting suspected that there is a problem:
Copy CodeThe code is as follows:
<value name= "Request_terminate_timeout" >30s</value>
Check official documents: Http://php-fpm.org/wiki/Configuration_File
Copy CodeThe code is as follows:
Request_terminate_timeout-the timeout (in seconds) for serving a single request after which the worker process would be t Erminated. Should is used when the ' max_execution_time ' ini option does not the stop script execution for some reason. Default: "5s". Note: ' 0s ' means ' off '
The main idea is that PHP in Set_time_limit set the time if PHP has not finished, then go to the configuration here, that is, request_terminate_timeout=30 seconds.
First change this parameter and PHP in the same set_time_limit value, are 300 seconds, not yet, do not understand why, if the master know please enlighten.
Finally, the Request_terminate_timeout closed, the program can be executed normally, problem solving:
Copy CodeThe code is as follows:
<value name= "Request_terminate_timeout" >0s</value>
Add: If the Nginx server on the front end uses upstream load balancing, the following parameters in that load balancer configuration need to be modified accordingly:
Copy CodeThe code is as follows:
Proxy_connect_timeout 300s;
Proxy_send_timeout 300s;
Proxy_read_timeout 300s;
Nginx quoted 504 Gateway timeout error 2