开发者

Are PHP scripts run using the "php" command affected by the timeout limit?

开发者 https://www.devze.com 2023-03-06 11:00 出处:网络
Are PHP scripts run using the \"php\" command affected by the timeout limit? I plan to sched开发者_StackOverflowule php scripts using cron.Yes, but you can set an unlimited timeout by adding this to t

Are PHP scripts run using the "php" command affected by the timeout limit? I plan to sched开发者_StackOverflowule php scripts using cron.


Yes, but you can set an unlimited timeout by adding this to the top of your script:

set_time_limit(0);


Some systems, such as Ubuntu, actually already start with separate CLI and Apache configurations in /etc/php5.

The relevant command in the ini file is:

max_execution_time = 30      ; Maximum execution time of each script, in seconds

However, if you are unable to modify the php.ini for whatever reason, you can create a new php.ini with configuration settings favourable to the command-line, and point to the file like so:

php -c /path/to/ini/php.ini -f script.php

Or, you can use Cailin's solution, and set the time limit at the top of the file - but if you are running on a server with PHP 'safe mode' enabled, then you will have to use your own ini file.


Depends. If your php binary is the PHP CLI interface, the default max_execution_time is zero (meaning there is no limit).

On the other hand, if it's the older-style CGI binary, you will be affected by the max_execution_time limit, and you'll need to call set_time_limit to get rid of it (assuming you're not in the dreaded PHP safe mode).

0

精彩评论

暂无评论...
验证码 换一张
取 消