tags:

views:

510

answers:

3

Hi. Is it possible to set maximum execution time of exec($command) function? Sometimes execution of my $command lasts too long and after 1min it stop execution and i receive this error:

Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\files.php on line 51

how to 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;
   }
+1  A: 

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.

soulmerge
how i can include ini_set() in my function?
robert
Insert the line wherever you like. No magic involved.
soulmerge
+4  A: 

See http://de2.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 functions 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);
Gordon
ok i put set_time_limit(180) before exec($command); It seems to work!but after the time expires i want to echo a error how i do this??
robert
It will throw an error by itself when the time limit expires. That's what made you ask your question in the first place. If you want a custom error handler, see http://de2.php.net/manual/en/function.set-error-handler.php
Gordon
yes, but when i submit a form a process.php page start with a iframe, i only whant to echo this: <script language="javascript" type="text/javascript">window.top.window.aviout('$result');</script> where the result is a error or succes!
robert
If `set_error_hander` doesn't help, then I'm afraid I don't understand. Consider opening a new question, as it is a different problem.
Gordon
+1  A: 

In .htaccess you can set these values:

php_value max_execution_time 1000000
php_value max_input_time 1000000

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

set_time_limit(0;)
John Conde