php-fcgi The execution time setting method of PHP

Source: Internet
Author: User
Tags nginx server

Yesterday, a program needs to export 500 data, the results found that 150 is, Nginx reported 504 Gateway timeout error, the original php-fcgi under the setting execution time differs from the ISAPI

In general, set the time when PHP script execution times out

One, in the php.ini inside set

max_execution_time = 1800;
Second, through the PHP ini_set function set

Ini_set ("Max_execution_time", "1800");
Third, through the Set_time_limit function set

Set_time_limit (1800);

php-fcgi The execution time setting method of PHP

Yesterday, a program needs to export 500 data, the results found that 150 is, Nginx reported 504 Gateway timeout error

It was observed that time-outs of about 30 seconds were found, and the execution times in php.ini were 300 seconds:

Max_execution_time = 300

Re-check the relevant configuration of nginx, no fruit.

I wrote a test page for PHP and then measured it.

Echo ' AAA '; Set_time_limit (0); Sleep (a); Echo ' AA ';

Still timeout, you can determine that the Set_time_limit function is not effective.

Re-check the configuration of php-fcgi php-fpm.conf, the bottom of this setup suspect a problem

<value name= "Request_terminate_timeout" >30s</VALUE>

Check official documents: Http://php-fpm.org/wiki/Configuration_File

 for  for Default

The main idea is that PHP in Set_time_limit set the time if PHP has not finished, then go to the configuration here, that is, request_terminate_timeout=30 seconds.
First change this parameter and PHP in the same set_time_limit value, are 300 seconds, not yet, do not understand why, if the master know please enlighten.

Finally the Request_terminate_timeout closed, the program can be executed normally, problem solving

<value name= "Request_terminate_timeout" >0s</VALUE>

Add: If the Nginx server on the front-end uses upstream load balancing, the following parameters in that load balancer configuration need to be modified accordingly

Proxy_connect_timeout       300s;  Proxy_send_timeout          300s;   Proxy_read_timeout          

php-fcgi The execution time setting method of PHP

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.