php.ini 核心配置选项说明

该列表只包含核心的 php.ini 配置选项。扩展的配置选项在各个扩展的文档页面分别被描述。有关 session 的选项可以在 sessions 页面找到。

Httpd 选项

表格 G-3. Httpd 选项

名称默认值可修改范围更新记录
async_send"0"PHP_INI_ALL 

语言选项

表格 G-4. 语言和杂类配置选项

名称默认值可修改范围更新记录
short_open_tag"1"PHP_INI_PERDIR在 PHP <= 4.0.0 时是 PHP_INI_ALL。
asp_tags"0"PHP_INI_PERDIR在 PHP <= 4.0.0 时是 PHP_INI_ALL。
precision"14"PHP_INI_ALL 
y2k_compliance"1"PHP_INI_ALL 
allow_call_time_pass_reference"1"PHP_INI_PERDIR在 PHP <= 4.0.0 时是 PHP_INI_ALL。
expose_php"1"仅可在 php.ini 中配置。 
zend.ze1_compatibility_mode"0"PHP_INI_ALL从 PHP 5.0.0 起可用。

以下是配置选项的简要解释。

short_open_tag boolean

决定是否允许使用 PHP 代码开始标志的缩写形式(<? ?>)。如果要和 XML 结合使用 PHP,可以禁用此选项以便于嵌入使用 <?xml ?>。否则还可以通过 PHP 来输出,例如:<?php echo '<?xml version="1.0"'; ?>。如果禁用了,必须使用 PHP 代码开始标志的完整形式(<?php ?>)。

注: 本指令也会影响到缩写形式 <?=,它和 <? echo 等价。使用此缩写需要 short_open_tag 的值为 On。

asp_tags boolean

除了通常的 <?php ?> 标志之外还允许使用 ASP 风格的标志 <% %>。这也包括了输出变量值的缩写 <%= $value %>。更多信息见从 HTML 中分离一节。

注: ASP 风格标志的支持是 3.0.4 版新加的。

precision integer

浮点数中显示有效数字的位数。

y2k_compliance boolean

强制 2000 年兼容(在不兼容的浏览器中会出问题)。

allow_call_time_pass_reference boolean

是否启用在函数调用时强制参数被按照引用传递。此方法已不被赞成并在 PHP/Zend 未来的版本中很可能不再支持。鼓励使用的方法是在函数定义中指定哪些参数应该用引用传递。鼓励大家尝试关闭此选项并确保脚本能够正常运行,以确保该脚本也能在未来的版本中运行(每次使用此特性都会收到一条警告,参数会被按值传递而不是按照引用传递)。

在函数调用时通过引用传递参数是不推荐的,因为它影响到了代码的整洁。如果函数的参数没有声明作为引用传递,函数可以通过未写入文档的方法修改其参数。要避免其副作用,最好仅在函数声明时指定那个参数需要通过引用传递。

参见引用的解释

expose_php boolean

决定是否暴露 PHP 被安装在服务器上(例如在 Web 服务器的信息头中加上其签名)。没有任何安全上的威胁,只是让客户端能够知道是否在服务器中安装了 PHP。

zend.ze1_compatibility_mode boolean

启用 Zend 引擎 1 (PHP 4) 兼容模式。这影响到了对象的复制、构造及比较。

参见从 PHP 4 移植到 PHP 5

资源限制

表格 G-5. 资源限制

名称默认值可修改范围更新记录
memory_limit"8M"PHP_INI_ALL 

以下是配置选项的简要解释。

memory_limit integer

本指令设定了一个脚本所能够申请到的最大内存字节数。这有助于防止写得不好的脚本消耗光服务器上的可用内存。要使用此指令必须在编译的时候激活。因此 configure 一行中应该包括:--enable-memory-limit。如果不需要任何内存上的限制,必须将其设为 -1。

自 4.3.2 起,当激活了 memory_limit,PHP 函数 memory_get_usage() 便可以使用了。

当使用 integer 类型时,其值以字节为度量单位。还可以用简化符号,说明见此 FAQ

See also: max_execution_time.

数据处理

表格 G-6. 数据处理配置选项

名称默认值可修改范围更新记录
track_vars"On"PHP_INI_?? 
arg_separator.output"&"PHP_INI_ALL从 PHP 4.0.5 起可用。
arg_separator.input"&"PHP_INI_PERDIR从 PHP 4.0.5 起可用。
variables_order"EGPCS"PHP_INI_ALL 
auto_globals_jit"1"PHP_INI_PERDIR从 PHP 5.0.0 起可用。
register_globals"0"PHP_INI_PERDIR在 PHP <= 4.2.3 时是 PHP_INI_ALL。
register_argc_argv"1"PHP_INI_PERDIR在 PHP <= 4.2.3 时是 PHP_INI_ALL。
register_long_arrays"1"PHP_INI_PERDIR从 PHP 5.0.0 起可用。
post_max_size"8M"PHP_INI_PERDIR在 PHP <= 4.2.3 时是 PHP_INI_ALL。从 PHP 4.0.3 起可用。
gpc_order"GPC"PHP_INI_ALL 
auto_prepend_fileNULLPHP_INI_PERDIR在 PHP <= 4.2.3 时是 PHP_INI_ALL。
auto_append_fileNULLPHP_INI_PERDIR在 PHP <= 4.2.3 时是 PHP_INI_ALL。
default_mimetype"text/html"PHP_INI_ALL 
default_charset""PHP_INI_ALL 
always_populate_raw_post_data"0"PHP_INI_PERDIR在 PHP <= 4.2.3 时是 PHP_INI_ALL。从 PHP 4.1.0 起可用。
allow_webdav_methods"0"PHP_INI_PERDIR 

以下是配置选项的简要解释。

track_vars boolean

如果激活,则环境变量,GET,POST,Cookie 和 Server 变量都能够分别在全局关联数组中找到:$_ENV$_GET$_POST$_COOKIE$_SERVER

注意自 PHP 4.0.3 起,track_vars 总是打开的。

arg_separator.output string

PHP 所产生的 URL 中来分隔参数的分隔符。

arg_separator.input string

PHP 用来将 URL 解析为变量的分隔符列表。

注: 本指令中的每个字符都会被当成分隔符!

variables_order string

设定 EGPCS(Environment,GET,POST,Cookie,Server)变量解析的顺序。默认设定为“EGPCS”。举例说,将其设为“GP”,会导致 PHP 完全忽略环境变量,cookies 和 server 变量,并用 GET 方法的变量覆盖 POST 方法的同名变量。

参见 register_globals

auto_globals_jit boolean

启用后,SERVER 和 ENV 变量在他们第一次使用后 (Just In Time) 便被创建,而不是等到脚本开始运行时。如果这些变量没有在脚本总使用,启用这个变量会提高服务器性能。

要使此选项有效,PHP 配置选项 register_globals, register_long_arrays, 和 register_argc_argv 必须禁用。

register_globals boolean

决定是否将 EGPCS(Environment,GET,POST,Cookie,Server)变量注册为全局变量。

PHP 4.2.0 开始,本选项默认为 off

相关信息请阅读安全一章中的使用 register_globals

请注意 register_globals 不能在运行时设定(ini_set()),尽管如以上说明在主机允许时可以用 .htaccess。一个 .htaccess 项目的例子:php_flag register_globals off

注: register_globalsvariables_order 选项的影响。

register_argc_argv boolean

决定 PHP 是否定义 argv & argc 变量(可能包含有 GET 信息)。

参见命令行方式。此外,本选项自 PHP 4.0.0 起可用,在此之前总是“On”。

register_long_arrays boolean

设定 PHP 是否注册已过时的 $HTTP_*_VARS 之类的预定义变量。如果为 On(默认值),则类似 $HTTP_GET_VARS 的 PHP 变量会被注册。如果不使用,为性能考虑建议关闭此选项,而使用超全局数组例如 $_GET 替代之。

本指令自 PHP 5.0.0 起可用。

post_max_size integer

设定 POST 数据所允许的最大大小。此设定也影响到文件上传。要上传大文件,该值必须大于 upload_max_filesize

如果配置脚本中激活了内存限制,memory_limit 也会影响文件上传。通常说,memory_limit 应该比 post_max_size 要大。

当使用 integer 类型时,其值以字节为度量单位。还可以用简化符号,说明见此 FAQ

如果 POST 数据尺寸大于 post_max_size $_POST$_FILES superglobals 便会为空。这可以以多种方式证明,例如,传递 $_GET 变量到脚本以处理数据, 也就是 <form action="edit.php?processed=1">, 然后查看 $_GET['processed'] 是否被设置。

gpc_order string

设定 GET/POST/COOKIE 变量解析的顺序,默认为“GPC”。举例说,将其设为“GP”,会导致 PHP 完全忽略 cookie 变量,并用 GET 方法的变量覆盖 POST 方法的同名变量。

注: 本选项不能用于 PHP 4。用 variables_order 替代之。

auto_prepend_file string

指定在主文件之前自动解析的文件名。该文件就像调用了 include() 函数一样被包含进来,因此会使用 include_path

特殊值 none 禁止了自动前缀。

auto_append_file string

指定在主文件之后自动解析的文件名。该文件就像调用了 include() 函数一样被包含进来,因此会使用 include_path

特殊值 none 禁止了自动后缀。

注: 如果脚本通过 exit() 终止,则自动后缀不会发生。

default_mimetype string

default_charset string

自 4.0b4 起,PHP 总是默认在 HTTP 信息头 Content-type: 中输出字符编码。要禁止发送字符集,将本选项设为空即可。

always_populate_raw_post_data boolean

总是产生 $HTTP_RAW_POST_DATA 变量包含有原始的 POST 数据。否则,此变量仅在碰到未识别 MIME 类型的数据时产生。不过,访问原始 POST 数据的更好方法是 php://input$HTTP_RAW_POST_DATA 对于 enctype="multipart/form-data" 表单数据不可用。

allow_webdav_methods boolean

允许在 PHP 脚本中处理 WebDAV 的 HTTP 请求(例如 PROPFIND,PROPPATCH,MOVE,COPY 等)。此选项在 PHP 4.3.2 以后便不存在了。如果要取得这些请求的 POST 数据,也要设定 always_populate_raw_post_data

参见 magic_quotes_gpcmagic-quotes-runtimemagic_quotes_sybase

路径和目录

表格 G-7. 路径和目录配置选项

名称默认值可修改范围更新记录
include_path".;/path/to/php/pear"PHP_INI_ALL 
doc_rootNULLPHP_INI_SYSTEM 
user_dirNULLPHP_INI_SYSTEM 
extension_dir"/path/to/php"PHP_INI_SYSTEM 
cgi.fix_pathinfo"1"PHP_INI_ALL 
cgi.force_redirect"1"PHP_INI_ALL 
cgi.redirect_status_envNULLPHP_INI_ALL 
fastcgi.impersonate"0"PHP_INI_ALL 
cgi.rfc2616_headers"0"PHP_INI_ALL 

以下是配置选项的简要解释。

include_path string

指定一组目录用于 require()include()fopen_with_path() 函数来寻找文件。格式和系统的 PATH 环境变量类似:一组目录的列表,在 UNIX 下用冒号分隔,在 Windows 下用分号分隔。

例子 G-1. Unix include_path

include_path=".:/php/includes"

例子 G-2. Windows include_path

include_path=".;c:\php\includes"

在包含路径中使用 . 可以允许相对路径,它代表当前目录。

doc_root string

PHP 在服务器上的根目录。仅在非空时使用。如果 PHP 被配置为安全模式,则此目录之外的文件一概不被解析。如果 PHP 编译时没有指定 FORCE_REDIRECT,并且在任何 web 服务器(除了 IIS)中以 CGI 方式运行 PHP,则应该设定 doc_root。替代方案是使用下面的 cgi.force_redirect 配置选项。

user_dir string

在用户目录之下使用 PHP 文件的基本目录名,例如 public_html

extension_dir string

PHP 用来寻找动态连接扩展库的目录。参见 enable_dldl()

extension string

当 PHP 启动时所加载的动态连接扩展库。

cgi.fix_pathinfo boolean

对 CGI 提供了真正的 PATH_INFO/PATH_TRANSLATED 支持。以前 PHP 的行为是将 PATH_TRANSLATED 设为 SCRIPT_FILENAME,而不管 PATH_INFO 是什么。有关 PATH_INFO 的更多信息见 cgi 规格。将此值设为 1 将使 PHP CGI 修正其路径以遵守规格。设为 0 将使 PHP 的行为和从前一样。默认为零。用户应该修正其脚本使用 SCRIPT_FILENAME 而不是 PATH_TRANSLATED。

cgi.force_redirect boolean

在大多数 web 服务器中以 CGI 方式运行 PHP 时很有必要用 cgi.force_redirect 提供安全。PHP 默认其为 On。可以将其关闭,但风险自担

注: Windows 用户:可以安全地在 IIS 之下将其关闭,事实上必须这么做。要在 OmniHTTPD 或 Xitami 之下使用也必须将其关闭。

cgi.redirect_status_env string

如果打开了 cgi.force_redirect,并且不是在 Apache 或 Netscape(iPlanet)web 服务器之下运行,可能需要设定一个环境变量名,PHP 将去寻找它来知道可以继续执行下去。

注: 设定此变量可能会导致安全问题,首先要知道自己在做什么。

fastcgi.impersonate string

IIS(在基于 WINNT 的操作系统上)中的 FastCGI 支持模仿客户端安全令牌的能力。这使得 IIS 能够定义运行时所基于的请求的安全上下文。Apache 中的 mod_fastcgi 不支持此特性(03/17/2002)。如果在 IIS 中运行则设为 1。默认为 0。

cgi.rfc2616_headers int

指定 PHP 在发送 HTTP 响应代码时使用何种报头。如果设定为 0,PHP 发送一个 Status: 报头,Apache 和其它 web server 都支持。如果此选项设定为 1,PHP 将发送 RFC 2616 兼容的报头。除非你知道自己在做什么,否则保留其值为 0。

文件上传

表格 G-8. 文件上传配置选项

名称默认值可修改范围更新记录
file_uploads"1"PHP_INI_SYSTEM在 PHP <= 4.2.3 时是 PHP_INI_ALL。从 PHP 4.0.3 起可用。
upload_tmp_dirNULLPHP_INI_SYSTEM 
upload_max_filesize"2M"PHP_INI_PERDIR在 PHP <= 4.2.3 时是 PHP_INI_ALL。

以下是配置选项的简要解释。

file_uploads boolean

是否允许 HTTP 文件上传。参见 upload_max_filesizeupload_tmp_dirpost_max_size 指令。

当使用 integer 类型时,其值以字节为度量单位。还可以用简化符号,说明见此 FAQ

upload_tmp_dir string

文件上传时存放文件的临时目录。必须是 PHP 进程所有者用户可写的目录。如果未指定则 PHP 使用系统默认值。

upload_max_filesize integer

所上传的文件的最大大小。

当使用 integer 类型时,其值以字节为度量单位。还可以用简化符号,说明见此 FAQ

普通 SQL

表格 G-9. 普通 SQL 配置选项

名称默认值可修改范围更新记录
sql.safe_mode"0"PHP_INI_SYSTEM 

以下是配置选项的简要解释。

sql.safe_mode boolean

调试器配置选项

注意

仅 PHP 3 实现了一个默认的调试器。更多信息请参考附录 E

debugger.host string

调试器所使用的主机的 DNS 名或 IP 地址。

debugger.port string

调试器所用的端口号。

debugger.enabled boolean

是否启用调试器。


add a note add a note User Contributed Notes
xangelusx at hotmail dot com
24-Jul-2006 10:28
I wish the documentation was more clear as to whether the arg_separator.output character is automatically encoded when PHP outputs it. In other words, is "&" valid or do I need to specify the encoded character "&amp;"? It would make sense to specify only "&" and hope that it is encoded as needed. That way the value could be read by other functions and encoded only when output to HTML, rather than having to test whether it is already encoded and decode it when necessary (for header redirection for example)
leo at korfu dot cz
30-May-2006 06:45
"If the size of post data is greater than post_max_size..."

It seems that a more elegant way is comparison between post_max_size and $_SERVER['CONTENT_LENGTH']. Please note that the latter includes not only size of uploaded file plus post data but also multipart sequences. Leo
csg at DEL_THISdiatom dot de
02-Sep-2005 05:55
Starting with PHP 4.4.0 (at least PHP version 4.3.10 did have old, documented behaviour) interpretation of value of "session.save_path" did change in conjunction with "save_mode" and "open_basedir" enabled.

Documented ( http://de.php.net/manual/en/ref.session.php#ini.session.save-path ):
  Values of "session.save_path" should or may be  **without**  ending slash.
  For instance:
<?php
 
// Valid only  *before* PHP 4.4.0:
 
ini_set( "session.save_path", "/var/httpd/kunde/phptmp" );
?> will mean:
  The directory "/var/httpd/kunde/phptmp/" will be used to write data and therefore must be writable by the web server.

Starting with PHP 4.4.0 the server complains that "/var/httpd/kunde/" is not writable.
Solution: Add an ending slash in call of ini_set (or probably whereever you set "session.save_path"), e.g.:
<?php
 
// Note the slash on ".....phptmp/":
 
ini_set( "session.save_path", "/var/httpd/kunde/phptmp/" );
?>

Hope, that does help someone.
Manu
27-Jul-2005 08:02
Warning, if you change upload_max_filesize, please note that both post_max_size and memory_limit directives may have to change too.
david dot tulloh at infaze dot com dot au
27-Jun-2005 09:19
I did a little experimentation on the behaviour of auto_prepend_file as the order of access wasn't clear to me from the documentation.

1. Apache checks to see if the target file exists.
2. The prepend file is called
3. The target file is called

This means that you can use auto_prepend_file to change the target file before you access it however you can't generate new files.
Joe
10-Jun-2005 04:05
Please be mindful, that if you plan on re-configuring / recompiling to add --enable-memory-limit support, you may need to run a 'make clean' before you run 'make'. Otherwise, you may end up with a phpinfo() that shows up with --enable-memory-limit as a configure parameter, but the memory_get_usage() function will still force a fatal error.