Questions about PHP execution timeouts

Source: Internet
Author: User
Tags comparison table stop script

PHP Config file parameter max_execution_time indicates script execution time-out

Max_execution_time=0 means no Limit

Max_execution_time=2 indicates that execution terminates after two seconds and error Fatal error: Maximum execution time of 2 seconds exceeded

However, the sleep (10) function does not work.

For example, the max_execution_time=2 in php.ini

Execute code <?php sleep; echo ' OK ';?> is not timed out (provided the Web server does not time out)

Execute Code <?php echo 1;for ($i =0; $i <100000000000; $i + +) {for ($i =0; $i <100000000000; $i + +) {}} echo 2;? > will time out, Output 1, and error

Note: the Set_time_limit () function can override the Max_execution_time parameter, can be larger than the Max_execution_time parameter, or it can be 0 without restriction, of course

When this function is called,Set_time_limit () Restarts the timeout counter starting from zero. In other words, if the timeout is 30 seconds by default, and when the script runs for 25 seconds, the script will run for a total of 45 seconds before timing out (set_time_limit) .

There is another situation

If PHP works in PHP-FPM mode, such as Web server is Nginx

The time-out also depends on the configuration in php-fpm.conf request_terminate_timeout

This parameter is explained as follows: Thetimeout for serving a single request after which the worker process would be killed. This option should is used when the ' max_execution_time ' ini option does not stop script execution for some Reaso N.

Presumably, if max_execution_time this parameter does not limit the execution of the script, it depends on the timeout of the parameter, for example, max_execution_time=0; or max_execution_time greater than request_ Terminate_timeout value, or sleep () in the program, the final timeout depends on the request_terminate_timeout parameter;

Of course, if the program is because the Request_terminate_timeout timeout is not content output, will be reported 502 error, 502 bad Gateway/nginx 1.7

In summary, summarize the following comparison table, if there is a wrong place, you are welcome to correct

 

Non-fpm

max_execution_time=4

fpm

Request_terminate_ti meout=8

max_execution_time=4

fpm

request_terminate_timeout=4

Max_execution_ Time=8

fpm

request_terminate_timeout=4

max_execution_time=0

<?php

Echo 1;sleep (+); Echo 2;

?

Output: output: 502 bad Gateway   Output: 502 bad Gateway   Output: 502 bad Gateway

<?php

Echo 1; $i =0;

while ($i ++<1000000000)

{//Assume it will take a long time}

Echo 2;

?

Output: 1

Fatal error : Maximum execution

Time of 4 seconds exceeded

Output: 1 

Fatal error : Maximum execution

Time of 4 seconds exceeded

  Output: 502 bad Gateway   Output: 502 bad Gateway

Questions about PHP execution timeouts

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.