以下是 PHP 二进制文件提供的命令行模式的选项参数,随时可以运行带 -h 参数的 PHP 命令来查询这些参数。
Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a
-a Run interactively
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse and execute <file>.
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-r <code> Run PHP <code> without using script tags <?..?>
-B <begin_code> Run PHP <begin_code> before processing input lines
-R <code> Run PHP <code> for every input line
-F <file> Parse and execute <file> for every input line
-E <end_code> Run PHP <end_code> after processing all input lines
-H Hide any passed arguments from external tools.
-S <addr>:<port> Run with built-in web server.
-t <docroot> Specify document root <docroot> for built-in web server.
-s Output HTML syntax highlighted source.
-v Version number
-w Output source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin
--ini Show configuration file names
--rf <name> Show information about function <name>.
--rc <name> Show information about class <name>.
--re <name> Show information about extension <name>.
--rz <name> Show information about Zend extension <name>.
--ri <name> Show configuration for extension <name>.
| 选项名称 | 长名称 | 说明 |
|---|---|---|
| -a | --interactive |
交互式运行 PHP。For more information, see the Interactive shell section. |
| -b | --bindpath |
Bind Path for external FASTCGI Server mode (CGI only). |
| -C | --no-chdir |
Do not chdir to the script's directory (CGI only). |
| -q | --no-header |
Quiet-mode. Suppress HTTP header output (CGI only). |
| -T | --timing |
Measure execution time of script repeated count times (CGI only). |
| -c | --php-ini |
用该参数,可以指定一个放置 php.ini
文件的目录,或者直接指定一个自定义的 $ php -c /custom/directory/ my_script.php $ php -c /custom/directory/custom-file.ini my_script.php 如果不指定此选项,php.ini 将在默认位置 搜索。 |
| -n | --no-php-ini |
完全忽略 php.ini。 |
| -d | --define |
用该参数可以自行设置任何可以在 php.ini 文件中设置的配置选项的值,其语法为: -d configuration_directive[=value]
# 取值部分被省略,将会把配置选项设为 "1"
$ php -d max_execution_time
-r '$foo = ini_get("max_execution_time"); var_dump($foo);'
string(1) "1"
# 取值部分为空白,将会把配置选项设为 ""
php -d max_execution_time=
-r '$foo = ini_get("max_execution_time"); var_dump($foo);'
string(0) ""
# 配置选项将被设置成为任何 '=' 字符之后的值
$ php -d max_execution_time=20
-r '$foo = ini_get("max_execution_time"); var_dump($foo);'
string(2) "20"
$ php
-d max_execution_time=doesntmakesense
-r '$foo = ini_get("max_execution_time"); var_dump($foo);'
string(15) "doesntmakesense"
|
| -e | --profile-info |
激活扩展信息模式,被用于调试/测试。 |
| -f | --file |
解析并运行 -f 选项给定的文件名。该参数为可选参数,可以省略,仅指明需要运行的文件名即可。
|
| -h and -? | --help and --usage | 使用该参数,可以得到完整的命令行参数的列表及这些参数作用的简单描述。 |
| -i | --info | 该命令行参数会调用 phpinfo() 函数并显示出结果。如果 PHP 没有正常工作,建议执行 php -i 命令来查看在信息表格之前或者对应的地方是否有任何错误信息输出。请注意当使用 CGI 摸索时,输出的内容为 HTML 格式,因此输出的信息篇幅较大。 |
| -l | --syntax-check |
该参数提供了对指定 PHP
代码进行语法检查的方便的方法。如果成功,则向标准输出写入
该参数将无法检查致命错误(如未定义函数),如果也希望检测致命错误,请使用 -f 参数。
|
| -m | --modules |
示例 #1 使用该参数,PHP 将打印出内置以及已加载的 PHP 及 Zend 模块: $ php -m [PHP Modules] xml tokenizer standard session posix pcre overload mysql mbstring ctype [Zend Modules] |
| -r | --run |
使用该参数可以在命令行内运行单行 PHP
代码。无需加上 PHP
的起始和结束标识符(
|
| -B | --process-begin |
在处理 stdin 之前先执行 PHP 代码。 |
| -R | --process-code |
对每个输入行都执行 PHP 代码。 此模式下有两个特殊变量:$argn 和 $argi。$argn 包含 PHP 当前处理的行内容,而 $argi 则包含该行号。 |
| -F | --process-file |
对每个输入行都执行 PHP 文件。 |
| -E | --process-end |
在处理完输入后执行的 PHP 代码。 示例 #4 使用 -B,-R 和 -E 选项来计算一个项目总行数的例子。 $ find my_proj | php -B '$l=0;' -R '$l += count(@file($argn));' -E 'echo "Total Lines: $l\n";' Total Lines: 37328 |
| -S | --server |
Starts built-in web server. |
| -t | --docroot | Specifies document root for built-in web server. |
| -s | --syntax-highlight and --syntax-highlighting |
显示有语法高亮色彩的源代码。
该参数使用内建机制来解析文件并为其生成一个 HTML
高亮版本并将结果写到标准输出。请注意该过程所做的只是生成了一个
|
| -v | --version |
示例 #5 使用 -v 将 PHP、SAPI 名称和 Zend 的版本信息写入标准输出。 $ php -v PHP 5.3.1 (cli) (built: Dec 11 2009 19:55:07) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies |
| -w | --strip |
显示除去了注释和多余空白的源代码。
|
| -z | --zend-extension |
加载 Zend 扩展库。如果仅给定一个文件名,PHP 将试图从当前系统扩展库的默认路径(在 Linux 系统下,该路径通常由 /etc/ld.so.conf 指定)加载该扩展库。如果用一个绝对路径指定文件名,则不会使用系统的扩展库默认路径。如果用相对路径指定的文件名,则 PHP 仅试图在当前目录的相对目录加载扩展库。 |
| --ini |
Show configuration file names and scanned directories. 示例 #6 $ php --ini Configuration File (php.ini) Path: /usr/dev/php/5.2/lib Loaded Configuration File: /usr/dev/php/5.2/lib/php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none) |
|
| --rf | --rfunction |
Show information about the given function or class method (e.g. number and name of the parameters). This option is only available if PHP was compiled with Reflection support.
示例 #7 basic $ php --rf var_dump
Function [ <internal> public function var_dump ] {
- Parameters [2] {
Parameter #0 [ <required> $var ]
Parameter #1 [ <optional> $... ]
}
}
|
| --rc | --rclass |
Show information about the given class (list of constants, properties and methods). This option is only available if PHP was compiled with Reflection support.
示例 #8 $ php --rc Directory
Class [ <internal:standard> class Directory ] {
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [0] {
}
- Methods [3] {
Method [ <internal> public method close ] {
}
Method [ <internal> public method rewind ] {
}
Method [ <internal> public method read ] {
}
}
}
|
| --re | --rextension |
Show information about the given extension (list of php.ini options, defined functions, constants and classes). This option is only available if PHP was compiled with Reflection support.
示例 #9 $ php --re json
Extension [ <persistent> extension #19 json version 1.2.1 ] {
- Functions {
Function [ <internal> function json_encode ] {
}
Function [ <internal> function json_decode ] {
}
}
}
|
| --rz | --rzendextension |
Show the configuration information for the given Zend extension (the same information that is returned by phpinfo()). |
| --ri | --rextinfo |
Show the configuration information for the given extension (the same information that is returned by phpinfo()). The core configuration information is available using "main" as extension name.
示例 #10 $ php --ri date date date/time support => enabled "Olson" Timezone Database Version => 2009.20 Timezone Database => internal Default timezone => Europe/Oslo Directive => Local Value => Master Value date.timezone => Europe/Oslo => Europe/Oslo date.default_latitude => 59.930972 => 59.930972 date.default_longitude => 10.776699 => 10.776699 date.sunset_zenith => 90.583333 => 90.583333 date.sunrise_zenith => 90.583333 => 90.583333 |
注意:
Options
-rBRFEH,--iniand--r[fcezi]are available only in CLI.