Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
593 views
in Technique[技术] by (71.8m points)

linux - Set max_execution_time in PHP CLI

I know that PHP CLI is usually used because of none time limits and primary because it is not using Apache threads/processes.

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?

If you think this question may be better answered on superuser.com and have permission to move it, do it. :)

Edit: I've been Googling a bit and found the right parameter:

php -d max_execution_time=5 script.php
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Edit: I just tried it myself, and it works as expected.

F:devwww>c:php -f index.php
PHP Fatal error:  Maximum execution time of 2 seconds exceeded in F:devwwwindex.php on line 3

Fatal error: Maximum execution time of 2 seconds exceeded in F:devwwwindex.php on line 3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...