在PHP CLI中设置max_execution_time [英] Set max_execution_time in PHP CLI
问题描述
我知道通常使用PHP CLI是因为没有时间限制,而主要使用PHP CLI是因为它没有使用Apache线程/进程.
I know that PHP CLI is usually used because of none time limits and primary because it is not using Apache threads/processes.
但是有什么方法可以为某些我不想拥有无限时间"自由而只想让那些脚本受到控制的脚本显式设置max_execution_time吗?
But is there any way how to explicitly set the max_execution_time for some scripts which i don't want to have the freedom of "unlimited time" and just want to keep those script under control?
如果您认为在superuser.com上可以更好地回答此问题,并有权移动它,请执行此操作. :)
If you think this question may be better answered on superuser.com and have permission to move it, do it. :)
编辑:我已经在Google上进行了一段时间的搜索,并找到了正确的参数:
Edit: I've been Googling a bit and found the right parameter:
php -d max_execution_time=5 script.php
推荐答案
文档表示,在命令行模式下运行时,默认值为0(无限制).它并不表示您无法覆盖它:
The documentation says that when running in command line mode, the default is 0 (unlimited). It doesn't say that you cannot override it:
set_time_limit(10); // this way
ini_set('max_execution_time', 10); // or this way
我只是亲自尝试过,它可以按预期工作.
I just tried it myself, and it works as expected.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!