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

天大地大妈咪最大 提交于 2019-12-04 19:25:29

问题


Are PHP scripts run using the "php" command affected by the timeout limit? I plan to schedule php scripts using cron.


回答1:


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

set_time_limit(0);



回答2:


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.




回答3:


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).



来源:https://stackoverflow.com/questions/6039224/are-php-scripts-run-using-the-php-command-affected-by-the-timeout-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!