专门设置exec()的最大执行时间 [英] Set maximum execution time for exec() specifically

查看:382
本文介绍了专门设置exec()的最大执行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以设置exec($command)函数的最大执行时间?有时我的$command的执行持续时间过长,一分钟后停止并出现此错误:

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:

致命错误:第51行的C:\ xampp \ htdocs \ files.php中超过60秒的最大执行时间

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

如何增加exec()命令的最大执行时间?

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;
   }

推荐答案

请参见 http://php.net/manual/zh/function.set-time-limit.php

set_time_limit($seconds)

如果将$second设置为0,则没有时间限制.请注意,您应谨慎删除所有时间限制.您不希望任何无限循环慢慢耗尽所有服务器资源.上限,例如180比没有限制要好.

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);

这篇关于专门设置exec()的最大执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆