How to set the execution time of PHP under PHP-Fcgi_PHP tutorial

WBOY
Release: 2016-07-21 15:00:08
Original
973 people have browsed it

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:

Copy code The code is as follows:
max_execution_time = 300

Checking the relevant configuration of nginx again, to no avail.

Write a php test page and test again

Copy code The code is as follows:

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

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

Copy code The code is as follows:

30s

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

Copy code 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. Should be used when 'max_execution_time' ini option does not stop script execution for some reason. Default: "5s". Note: '0s' means 'off'

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

Copy code The code is as follows:
0s

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

Copy code The code is as follows:

proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_ timeout 300s;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328087.htmlTechArticleGenerally, set the PHP script execution timeout time 1. Set max_execution_time = 1800 in php.ini; 2. Set ini_set("max_execution_time", "18...
through PHP's ini_set function)
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!