Home > Article > Backend Development > How to set the execution time of PHP under PHP-Fcgi_PHP tutorial
Generally, set the PHP script execution timeout
1. Set in php.ini
max_execution_time = 1800;
2. Set through PHP’s ini_set function
ini_set("max_execution_time", "1800");
3. Set through the set_time_limit function
set_time_limit(1800);
How to set the execution time of PHP under PHP-Fcgi
Yesterday, a program needed to export 500 pieces of data. It was found that 150 pieces of data were exported, and Nginx reported a 504 Gateway Timeout error
After observation, it was found that the timeout occurs at about 30 seconds, and the execution time configuration in php.ini is already 300 seconds:
Checking the relevant configuration of nginx again, to no avail.
Write a php test page and test again
It still times out. It can be determined that the set_time_limit function does not take effect.
Check the configuration php-fpm.conf of php-fcgi again, there seems to be a problem with the setting below
Check the official documentation: http://php-fpm.org/wiki/Configuration_File
The general idea is that if php has not been executed within the time set by set_time_limit in php, then the configuration here will be used, that is, request_terminate_timeout=30 seconds.
First change this parameter to be the same as the set_time_limit value in php, which is 300 seconds. It still doesn’t work. I don’t understand why. If an expert knows, please let me know.
Finally, request_terminate_timeout is turned off, the program can be executed normally, and the problem is solved
Supplement: If the front-end nginx server uses upstream load balancing, the following parameters in the load balancing configuration also need to be modified accordingly