Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

exec

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 time 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;
   }
like image 810
robert Avatar asked Feb 04 '10 18:02

robert


3 Answers

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);
like image 53
Gordon Avatar answered Oct 21 '22 18:10

Gordon


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);
like image 39
John Conde Avatar answered Oct 21 '22 19:10

John Conde


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.

like image 33
soulmerge Avatar answered Oct 21 '22 19:10

soulmerge