-1
php -f script.php param1 param2

目前,我只是在检查是否isset($argv). 这是最好的方法吗?

PS我还想知道所有输入参数是否总是存储在$argv

4

2 回答 2

1

正如您可以在此处阅读的那样,有什么方法可以知道 php 脚本是否在 cli 模式下运行?你可以使用这个功能:

function is_cli()
{
    return php_sapi_name() === 'cli';
}
于 2012-09-18T10:36:03.717 回答
0

检查是否REQUEST_METHOD设置了 a:

/**
 * Check if the site is being visited (in a browser) or run as a program from the 
 * commandline.
 * @return boolean true if the request appears to come from the WWW, false if not.
 */
function is_web_request () {
    return isset($_SERVER['REQUEST_METHOD']);
}
于 2012-09-18T10:36:49.883 回答