手册没有说明这一点,但是,如果你想在CLI模式下运行时要注册$_SERVER [‘argc’],$_SERVER [‘argv’],$argc,$argv,那么需要在php.ini中启用php.ini值
register_argc_argv(默认为关闭[出于性能原因]).
您可以执行以下操作来获取argv或查询字符串args,具体取决于脚本的运行方式:
if (php_sapi_name() == 'cli') {
$args = $_SERVER['argv'];
} else {
parse_str($_SERVER['QUERY_STRING'], $args);
}
以下是php.ini的一些细节:
; This directive determines whether PHP registers $argv & $argc each time it
; runs. $argv contains an array of all the arguments passed to PHP when a script
; is invoked. $argc contains an integer representing the number of arguments
; that were passed when the script was invoked. These arrays are extremely
; useful when running scripts from the command line. When this directive is
; enabled, registering these variables consumes CPU cycles and memory each time
; a script is executed. For performance reasons, this feature should be disabled
; on production servers.
; Note: This directive is hardcoded to On for the CLI SAPI
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/register-argc-argv