In Nginx PHP Fcgi the 504 Gateway Timeout error resolution record is caused by the PHP execution time

  • 2020-05-09 19:52:36
  • OfStack

Yesterday, a program that needed to export 500 pieces of data found that 150 pieces of data were Nginx reporting a 504 Gateway Timeout error

After observation, it was found that the timeout was about 30 seconds, and the execution time configuration in php.ini was already 300 seconds:


max_execution_time = 300

Check the configuration of nginx again, no result.

Write a test page of php and test again:


echo 'aaa';
set_time_limit(0);
sleep(40);
echo 'aa';

Still timed out, you can be sure that the function set_time_limit is not in effect.

Check the configuration of php-fcgi again. php-fpm.conf.


<value name="request_terminate_timeout">30s</value>

Check the official documentation: http: / / php - fpm org/wiki/Configuration_File


request_terminate_timeout - The timeout (in seconds) for serving a single request after which the worker process will be terminated. Should be used when 'max_execution_time' ini option does not stop script execution for some reason. Default: "5s". Note: '0s' means 'off'

set_time_limit if php is not finished, then go to the configuration here, request_terminate_timeout=30 seconds.

First change this parameter and php set_time_limit value 1, are 300 seconds, not yet, do not understand why, if the master know please comment.

Finally, request_terminate_timeout was closed, and the program could be executed normally. The problem was solved:


<value name="request_terminate_timeout">0s</value>

Note: if the front-end nginx server USES upstream load balancing, the following parameters in that load balancing configuration also need to be modified accordingly:


proxy_connect_timeout       300s;
proxy_send_timeout          300s;
proxy_read_timeout          300s;


Related articles: