在PHP CLI中设置max_execution_time

我知道通常使用PHP CLI是因为没有时间限制,而主要使用PHP CLI是因为它没有使用Apache线程/进程。

但是,有什么方法可以为某些我不想拥有“无限时间”自由而只想让那些脚本受到控制的脚本显式设置max_execution_time?

如果您认为在superuser.com上可以更好地回答此问题,并有权移动它,请执行此操作。:)

:我一直在谷歌搜索了一下,找到正确的参数:

php -d max_execution_time=5 script.php

回答:

该文档说,在命令行模式下运行时,默认值为0(无限制)。它并不表示您不能覆盖它:

set_time_limit(10); // this way

ini_set('max_execution_time', 10); // or this way

我只是自己尝试过,它可以按预期工作。

F:\dev\www>c:php -f index.php

PHP Fatal error: Maximum execution time of 2 seconds exceeded in F:\dev\www\index.php on line 3

Fatal error: Maximum execution time of 2 seconds exceeded in F:\dev\www\index.php on line 3

以上是 在PHP CLI中设置max_execution_time 的全部内容, 来源链接: utcz.com/qa/424053.html

回到顶部