PHP execution time setting in PHP-Fcgi

Source: Internet
Author: User
Tags configuration php stop script
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.