问题描述
是否可以设置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:
如何增加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()的最大执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!