php-fcgi of PHP Execution time setting method _php skills

Source: Internet
Author: User
Tags configuration php fpm php script stop script nginx server

Generally set the time when the PHP script execution timeout

One, in 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);

How to set the execution time of PHP under php-fcgi

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

After observation, it was found that about 30 seconds timed out, the execution time in php.ini is 300 seconds:

Copy Code code as follows:
Max_execution_time = 300

Check the related configuration of nginx, no fruit.

I wrote a test page for PHP.

Copy Code code as follows:

Echo ' AAA ';
Set_time_limit (0);
Sleep (40);
echo ' AA ';

Still timeout, you can determine set_time_limit This function is not effective.

Again check php-fcgi configuration php-fpm.conf, the bottom of this setting is suspected to be problematic

Copy Code code as follows:

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

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

Copy Code code as follows:

Request_terminate_timeout-the timeout (in seconds) for serving a single request after the which the worker process would be t Erminated. Should be used as ' max_execution_time ' ini option does not stop script execution for some reason. Default: "5s". Note: ' 0s ' means ' off '

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

Finally put the request_terminate_timeout shut down, the program can be implemented properly, problem solving

Copy Code code as follows:
<value name= "Request_terminate_timeout" >0s</VALUE>

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

Copy Code code as follows:

Proxy_connect_timeout 300s;
Proxy_send_timeout 300s;
Proxy_read_timeout 300s;

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.