开发者

Set maximum execution time for exec() specifically [duplicate]

This question already has answers here: Limit execution time of an function or command PHP (7 answers) Closed 9 years ago.

Is it possible to set maximum execution time of exec($command) function? Sometimes execution of my $command lasts too long stopping after 1 minute and presenting this error:

Fatal error: Maximum execution t开发者_运维问答ime of 60 seconds exceeded in C:\xampp\htdocs\files.php on line 51

How can I increase the exec() command maximum execution time?

    if (allow()) {
    exec($command);

    if (file_exists($file)) {
        //exec($makeflv);
        echo '<script language="javascript" type="text/javascript">window.top.window.aviout(1);</script>';

    } else {
        echo $error;
        }

} else {
   echo $error;
   }


See http://php.net/manual/en/function.set-time-limit.php

set_time_limit($seconds)

If $second is set to 0, no time limit is imposed. Note that you should be cautious with removing the time limit altogether. You don't want any infinite loops slowly eating up all server resources. A high limit, e.g. 180 is better than no limit.

Alternatively, you can adjust the time setting just for certain blocks of code and resetting the time limit after the time critical code has run, e.g.

$default = ini_get('max_execution_time');
set_time_limit(1000);
... some long running code here ...
set_time_limit($default);


In .htaccess you can set these values:

php_value max_execution_time 1000000
php_value max_input_time 1000000

You can also try this at the top of your PHP script:

set_time_limit(0);


you can use ini_set() like this:

ini_set('max_execution_time', 0);

Setting it to 0 will make your script run forever according to the documentation of the ini-directive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜