Yesterday, a program needs to export 500 pieces of data. as a result, 150 pieces of data are found. Nginx reports a 504GatewayTimeout error, in the past, the execution time set in PHP-Fcgi is different from that in isapi. Generally, the PHP script execution time-out period is set.
1. set in php. ini
Max_execution_time = 1800;
2. set through the ini_set function of PHP
Ini_set ("maid", "1800 ");
3. use the set_time_limit function to set
Set_time_limit (1800 );
PHP execution time setting in PHP-Fcgi
Yesterday, a program needs to export 500 pieces of data. as a result, 150 pieces of data are found. Nginx reports a 504 Gateway Timeout error.
It was observed that the execution time timed out in about 30 seconds, and the execution time in php. ini was 300 seconds:
The code is as follows:
Max_execution_time= 300
Check nginx configurations.
Write a php test page and test again
The code is as follows:
Echo 'AAA ';
Set_time_limit (0 );
Sleep (40 );
Echo 'A ';
Still timeout. you can confirm that the set_time_limit function does not take effect.
Check the configuration php-fpm.conf of php-fcgi again, the following settings are suspected to have problems
The code is as follows:
30 s
Search official documents: http://php-fpm.org/wiki/Configuration_File
The code is as follows:
Request_terminate_timeout-The timeout (in seconds) for serving a single request after which the worker process will be terminated. shocould be used when 'max _ execution_time 'ini option does not stop script execution for some reason. default: "5 s ". note: '0s' means 'off'
The general idea is that if php has not completed execution in the time set by set_time_limit in php, the configuration here is used, that is, request_terminate_timeout = 30 seconds.
This parameter is set to the same value as set_time_limit in php. it takes 300 seconds, but it still does not work. I don't understand why. if you know it, please kindly advise.
Finally, the request_terminate_timeout is closed, and the program can be executed normally. The problem is solved.
The code is as follows:
0 s
Supplement: if the front-end nginx server uses upstream server load balancer, the following parameters in the server load balancer configuration need to be modified accordingly.
The code is as follows:
Proxy_connect_timeout 300 seconds;
Proxy_send_timeout 300 s;
Proxy_read_timeout 300 seconds;