哈希空间 Ctrl + F 进行搜索
首页 php手册中文版 CSS中文手册 哈希文档 Markdown在线工具

php.ini 核心配置选项说明

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

注意:

以下列出了未设置 php.ini 时的默认值;开发环境和生产环境的 php.ini 值可能会有所不同。

语言选项

语言和杂类配置选项
名字 默认 可修改范围 更新日志
short_open_tag "1" PHP_INI_PERDIR  
precision "14" PHP_INI_ALL  
serialize_precision "-1" PHP_INI_ALL 在 PHP 7.1.0 以前,默认值为 17。
disable_functions "" 仅仅为 PHP_INI_SYSTEM  
disable_classes "" 仅仅为 php.ini  
exit_on_timeout "" PHP_INI_ALL  
expose_php "1" php.ini only  
hard_timeout "2" PHP_INI_SYSTEM 从 PHP 7.1.0 起可用
zend.exception_ignore_args "0" PHP_INI_ALL 从 PHP 7.4.0 起可用
zend.multibyte "0" PHP_INI_ALL  
zend.script_encoding NULL PHP_INI_ALL  
zend.detect-unicode NULL PHP_INI_ALL 从 PHP 5.4.0 起可用
zend.signal_check "0" PHP_INI_SYSTEM  
zend.assertions "1" PHP_INI_ALL  
zend.exception_string_param_max_len "15" PHP_INI_ALL 自 PHP 8.0.0 起可用。

这是配置指令的简短说明。

short_open_tag bool

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

注意:

本指令不会影响到缩写形式 <?=,因为它总是可用的。

precision int
浮点数中显示有效数字的位数。-1 means that an enhanced algorithm for rounding such numbers will be used.
serialize_precision int
The number of significant digits stored while serializing floating point numbers. -1 means that an enhanced algorithm for rounding such numbers will be used.
expose_php bool

决定是否暴露 PHP 被安装在服务器上(例如在 Web 服务器的信息头中加上其签名:X-Powered-By: PHP/5.3.7)。

disable_functions string

本指令可用于禁止某些函数。接受逗号分隔的函数名列表作为参数。

此指令仅能禁用 内置函数。 不能影响用户自定义函数

本指令只能设置在 php.ini 中。例如,无法在 httpd.conf 中设置。

disable_classes string
本指令可以使你禁用某些类。用逗号分隔类名。 本指令只能设置在 php.ini 中。例如不能将其设置在 httpd.conf
zend.assertions int
When set to 1, assertion code will be generated and executed (development mode). When set to 0, assertion code will be generated but it will be skipped (not executed) at runtime. When set to -1, assertion code will not be generated, making the assetions zero-cost (production mode).

注意:

If a process is started in production mode, zend.assertions cannot be changed at runtime, since the code for assertions was not generated.

If a process is started in development mode, zend.assertions cannot be set to -1 at runtime.

zend.exception_string_param_max_len int
The maximum length of string function arguments in stringified stack traces. Must range between "0" and "1000000".
hard_timeout int

When the timeout set in max_execution_time has been hit, the PHP runtime will tear down resources gracefully. If something gets stuck while this happens, the hard timeout will tick for the set amount of seconds. When the hard timeout is hit, PHP will exit ungracefully. When set to 0, the hard timeout will never activate.

When PHP stops from a hard timeout, it will look something like this:

Fatal error: Maximum execution time of 30+2 seconds exceeded (terminated) in Unknown on line 0
zend.exception_ignore_args bool

从异常产生的堆栈中排除参数。

zend.multibyte bool

启用多字节编码的源文件解析功能。启用 zend.multibyte 是使用 SJIS、BIG5 等在多字节字符串数据中包含特殊字符的字符编码所必需的。ISO-8859-1 兼容的编码,如 UTF-8、EUC 等,则不需要这个选项。

启用 zend.multibyte 需要 mbstring 扩展可用。

zend.script_encoding string

除非在脚本顶部出现 declare(encoding=...) 指令,否则将会使用此值。当使用不兼容 ISO-8859-1 的编码时,必须同时使用 zend.multibyte 和 zend.script_encoding。

文字字符串将从 zend.script_encoding 直译为 mbstring.internal_encoding,就像调用了 mb_convert_encoding() 一样。

zend.detect_unicode bool

Check for BOM (Byte Order Mark) and see if the file contains valid multibyte characters. This detection is performed before processing of __halt_compiler(). Available only in Zend Multibyte mode.

zend.signal_check bool

To check for replaced signal handlers on shutdown.

exit_on_timeout bool

这是一个用于 Apache 1 的 mod_php-only 指令,如果 PHP 执行超时,会强制 Apache 子程序退出.这样的超时会导致 Apache 1 内部的 longjmp() 调用,从而使一些扩展处于不一致的状态。通过终止进程,任何未完成的锁或内存将被清理。

资源限制

资源限制
名字 默认 可修改范围 更新日志
memory_limit "128M" PHP_INI_ALL  

这是配置指令的简短说明。

memory_limit int

设置了一个脚本允许分配的最大内存量,以字节(bytes)为单位。这有助于防止写得不好的脚本吃掉服务器上所有可用的内存。请注意,如果不需要内存限制,请将此指令设置为 -1

当使用 int 时, 其值以字节来衡量。还可以使用在 FAQ 中描述的速记符。

请参阅:max_execution_time

性能调整

性能调整
名字 默认 可修改范围 更新日志
realpath_cache_size "4M" PHP_INI_SYSTEM PPHP 7.0.16 和 7.1.2 之前,默认值为 "16K"
realpath_cache_ttl "120" PHP_INI_SYSTEM  

注意:

启用 open_basedir 将会 禁用 realpath cache。

这是配置指令的简短说明。

realpath_cache_size int

设定 PHP 使用的 realpath 缓存的大小。在 PHP 打开很多文件的系统中,这个值应该增加,以优化文件操作的数量。

这里的大小表示存储的路径字符串的总字节数,加上与缓存条目相关的数据大小。这意味着,为了在缓存中存储更长的路径,缓存大小必须更大。这个值不直接控制可以缓存的不同路径的数量。

缓存输入数据所需的大小取决于操作系统。

realpath_cache_ttl integer

缓存给定文件或目录的真实路径信息的持续时间(以秒为单位)。对于很少改变文件的系统,可以考虑增加该值。

数据处理

数据处理配置选项
名字 默认 可修改范围 更新日志
arg_separator.output "&" PHP_INI_ALL  
arg_separator.input "&" PHP_INI_PERDIR  
variables_order "EGPCS" PHP_INI_PERDIR  
request_order "" PHP_INI_PERDIR  
auto_globals_jit "1" PHP_INI_PERDIR  
register_argc_argv "1" PHP_INI_PERDIR  
enable_post_data_reading "1" PHP_INI_PERDIR  
post_max_size "8M" PHP_INI_PERDIR  
auto_prepend_file NULL PHP_INI_PERDIR  
auto_append_file NULL PHP_INI_PERDIR  
default_mimetype "text/html" PHP_INI_ALL  
default_charset "UTF-8" PHP_INI_ALL  
input_encoding "" PHP_INI_ALL  
output_encoding "" PHP_INI_ALL  
internal_encoding "" PHP_INI_ALL  

这是配置指令的简短说明。

arg_separator.output string

在 PHP 生成的 URL 中用来分隔参数的分隔符。

arg_separator.input string

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

注意:

本指令中的每一个字符都被视为分隔符!

variables_order string

Sets the order of the EGPCS (Environment, Get, Post, Cookie, and Server) variable parsing. For example, if variables_order is set to "SP" then PHP will create the superglobals $_SERVER and $_POST, but not create $_ENV, $_GET, and $_COOKIE. Setting to "" means no superglobals will be set.

警告

In both the CGI and FastCGI SAPIs, $_SERVER is also populated by values from the environment; S is always equivalent to ES regardless of the placement of E elsewhere in this directive.

注意:

The content and order of $_REQUEST is also affected by this directive.

request_order string

This directive describes the order in which PHP registers GET, POST and Cookie variables into the _REQUEST array. Registration is done from left to right, newer values override older values.

If this directive is not set, variables_order is used for $_REQUEST contents.

Note that the default distribution php.ini files does not contain the 'C' for cookies, due to security concerns.

auto_globals_jit bool

When enabled, the SERVER, REQUEST, and ENV variables are created when they're first used (Just In Time) instead of when the script starts. If these variables are not used within a script, having this directive on will result in a performance gain.

警告

Usage of SERVER, REQUEST, and ENV variables is checked during the compile time so using them through e.g. variable variables will not cause their initialization.

register_argc_argv bool
Tells PHP whether to declare the argv & argc variables (that would contain the GET information). See also command line.
enable_post_data_reading bool
Disabling this option causes $_POST and $_FILES not to be populated. The only way to read postdata will then be through the php://input stream wrapper. This can be useful to proxy requests or to process the POST data in a memory efficient fashion.
post_max_size int
Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. Generally speaking, memory_limit should be larger than post_max_size. 当使用 int 时, 其值以字节来衡量。还可以使用在 FAQ 中描述的速记符。 If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set.

注意:

PHP allows shortcuts for byte values, including K (kilo), M (mega) and G (giga). PHP will do the conversions automatically if you use any of these. Be careful not to exceed the 32 bit signed integer limit (if you're using 32bit versions) as it will cause your script to fail.

Changelog for post_max_size
版本 说明
5.3.4 post_max_size = 0 will not disable the limit when the content type is application/x-www-form-urlencoded or is not registered with PHP.
5.3.2 , 5.2.12 Allow unlimited post size by setting post_max_size to 0.
auto_prepend_file string

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require function, so include_path is used.

The special value none disables auto-prepending.

auto_append_file string

Specifies the name of a file that is automatically parsed after the main file. The file is included as if it was called with the require function, so include_path is used.

The special value none disables auto-appending.

注意: If the script is terminated with exit(), auto-append will not occur.

default_mimetype string

By default, PHP will output a media type using the Content-Type header. To disable this, simply set it to be empty.

PHP's built-in default media type is set to text/html.

default_charset string

"UTF-8" is the default value and its value is used as the default character encoding for htmlentities(), html_entity_decode() and htmlspecialchars() if the encoding parameter is omitted. The value of default_charset will also be used to set the default character set for iconv functions if the iconv.input_encoding, iconv.output_encoding and iconv.internal_encoding configuration options are unset, and for mbstring functions if the mbstring.http_input mbstring.http_output mbstring.internal_encoding configuration option is unset.

All versions of PHP will use this value as the charset within the default Content-Type header sent by PHP if the header isn't overridden by a call to header().

Setting default_charset to an empty value is not recommended.

input_encoding string

This setting is used for multibyte modules such as mbstring and iconv. Default is empty.

output_encoding string

This setting is used for multibyte modules such as mbstring and iconv. Default is empty.

internal_encoding string

This setting is used for multibyte modules such as mbstring and iconv. Default is empty. If empty, default_charset is used.

Paths and Directories

Paths and Directories Configuration Options
名字 默认 可修改范围 更新日志
include_path ".;/path/to/php/pear" PHP_INI_ALL  
open_basedir NULL PHP_INI_ALL  
doc_root NULL PHP_INI_SYSTEM  
user_dir NULL PHP_INI_SYSTEM  
user_ini.cache_ttl "300" PHP_INI_SYSTEM  
user_ini.filename ".user.ini" PHP_INI_SYSTEM  
extension_dir "/path/to/php" PHP_INI_SYSTEM  
extension NULL php.ini only  
zend_extension NULL php.ini only  
cgi.check_shebang_line "1" PHP_INI_SYSTEM  
cgi.discard_path "0" PHP_INI_SYSTEM  
cgi.fix_pathinfo "1" PHP_INI_SYSTEM  
cgi.force_redirect "1" PHP_INI_SYSTEM  
cgi.nph "0" PHP_INI_SYSTEM  
cgi.redirect_status_env NULL PHP_INI_SYSTEM  
cgi.rfc2616_headers "0" PHP_INI_ALL  
fastcgi.impersonate "0" PHP_INI_SYSTEM  
fastcgi.logging "1" PHP_INI_SYSTEM  

这是配置指令的简短说明。

include_path string

Specifies a list of directories where the require, include, fopen(), file(), readfile() and file_get_contents() functions look for files. The format is like the system's PATH environment variable: a list of directories separated with a colon in Unix or semicolon in Windows.

PHP considers each entry in the include path separately when looking for files to include. It will check the first path, and if it doesn't find it, check the next path, until it either locates the included file or returns with an E_WARNING or an E_ERROR. You may modify or set your include path at runtime using set_include_path().

示例 #1 Unix include_path

include_path=".:/php/includes"

示例 #2 Windows include_path

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

Using a . in the include path allows for relative includes as it means the current directory. However, it is more efficient to explicitly use include './file' than having PHP always check the current directory for every include.

注意:

ENV variables are also accessible in .ini files. As such it is possible to reference the home directory using ${LOGIN} and ${USER}.

Environment variables may vary between Server APIs as those environments may be different.

示例 #3 Unix include_path using ${USER} env variable

include_path = ".:${USER}/pear/php"
open_basedir string

Limit the files that can be accessed by PHP to the specified directory-tree, including the file itself. This directive is NOT affected by whether Safe Mode is turned On or Off.

When a script tries to access the filesystem, for example using include, or fopen(), the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to access it. All symbolic links are resolved, so it's not possible to avoid this restriction with a symlink. If the file doesn't exist then the symlink couldn't be resolved and the filename is compared to (a resolved) open_basedir.

open_basedir can affect more than just filesystem functions; for example if MySQL is configured to use mysqlnd drivers, LOAD DATA INFILE will be affected by open_basedir. Much of the extended functionality of PHP uses open_basedir in this way.

The special value . indicates that the working directory of the script will be used as the base-directory. This is, however, a little dangerous as the working directory of the script can easily be changed with chdir().

In httpd.conf, open_basedir can be turned off (e.g. for some virtual hosts) the same way as any other configuration directive with "php_admin_value open_basedir none".

Under Windows, separate the directories with a semicolon. On all other systems, separate the directories with a colon. As an Apache module, open_basedir paths from parent directories are now automatically inherited.

The restriction specified with open_basedir is a directory name, not a prefix.

The default is to allow all files to be opened.

注意:

open_basedir can be tightened at run-time. This means that if open_basedir is set to /www/ in php.ini a script can tighten the configuration to /www/tmp/ at run-time with ini_set(). When listing several directories, you can use the PATH_SEPARATOR constant as a separator regardless of the operating system.

注意:

Using open_basedir will set realpath_cache_size to 0 and thus disable the realpath cache.

警告

open_basedir 只是额外的安全保障,并不全面,因此在需要安全性时并不能依赖。

doc_root string

PHP's "root directory" on the server. Only used if non-empty. If PHP was not compiled with FORCE_REDIRECT, you should set doc_root if you are running PHP as a CGI under any web server (other than IIS). The alternative is to use the cgi.force_redirect configuration below.

user_ini.cache_ttl int

user_ini.filename string

user_dir string

The base name of the directory used on a user's home directory for PHP files, for example public_html .

extension_dir string

PHP 寻找可动态加载扩展的目录。建议指定绝对路径。参阅 enable_dldl()

extension string

Which dynamically loadable extensions to load when PHP starts up.

zend_extension string

Name of dynamically loadable Zend extension (for example XDebug) to load when PHP starts up.

cgi.check_shebang_line bool

Controls whether CGI PHP checks for line starting with #! (shebang) at the top of the running script. This line might be needed if the script support running both as stand-alone script and via PHP CGI. PHP in CGI mode skips this line and ignores its content if this directive is turned on.

cgi.discard_path bool

If this is enabled, the PHP CGI binary can safely be placed outside of the web tree and people will not be able to circumvent .htaccess security.

cgi.fix_pathinfo bool

Provides real PATH_INFO/ PATH_TRANSLATED support for CGI. PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. For more information on PATH_INFO, see the CGI specs. Setting this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting of zero causes PHP to behave as before. It is turned on by default. You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED.

cgi.force_redirect bool

cgi.force_redirect is necessary to provide security running PHP as a CGI under most web servers. Left undefined, PHP turns this on by default. You can turn it off at your own risk.

注意:

Windows Users: When using IIS this option must be turned off. For OmniHTTPD or Xitami the same applies.

cgi.nph bool

If cgi.nph is enabled it will force cgi to always sent Status: 200 with every request.

cgi.redirect_status_env string

If cgi.force_redirect is turned on, and you are not running under Apache or Netscape (iPlanet) web servers, you may need to set an environment variable name that PHP will look for to know it is OK to continue execution.

注意:

Setting this variable may cause security issues, know what you are doing first.

cgi.rfc2616_headers int

Tells PHP what type of headers to use when sending HTTP response code. If it's set to 0, PHP sends a » RFC 3875 "Status:" header that is supported by Apache and other web servers. When this option is set to 1, PHP will send » RFC 2616 compliant headers.

If this option is enabled, and you are running PHP in a CGI environment (e.g. PHP-FPM) you should not use standard RFC 2616 style HTTP status response headers, you should instead use their RFC 3875 equivalent e.g. instead of header("HTTP/1.0 404 Not found"); you should use header("Status: 404 Not Found");

Leave it set to 0 unless you know what you're doing.

fastcgi.impersonate string

FastCGI under IIS (on WINNT based OS) supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under. mod_fastcgi under Apache does not currently support this feature (03/17/2002) Set to 1 if running under IIS. Default is zero.

fastcgi.logging bool

Turns on SAPI logging when using FastCGI. Default is to enable logging.

File Uploads

File Uploads Configuration Options
名字 默认 可修改范围 更新日志
file_uploads "1" PHP_INI_SYSTEM  
upload_tmp_dir NULL PHP_INI_SYSTEM  
max_input_nesting_level 64 PHP_INI_PERDIR  
max_input_vars 1000 PHP_INI_PERDIR  
upload_max_filesize "2M" PHP_INI_PERDIR  
max_file_uploads 20 PHP_INI_PERDIR  

这是配置指令的简短说明。

file_uploads bool

Whether or not to allow HTTP file uploads. See also the upload_max_filesize, upload_tmp_dir, and post_max_size directives.

upload_tmp_dir string

The temporary directory used for storing files when doing file upload. Must be writable by whatever user PHP is running as. If not specified PHP will use the system's default.

If the directory specified here is not writable, PHP falls back to the system default temporary directory. If open_basedir is on, then the system default directory must be allowed for an upload to succeed.

upload_max_filesize int

上传文件的最大大小。

post_max_size 必须大于此值。

当使用 int 时, 其值以字节来衡量。还可以使用在 FAQ 中描述的速记符。
max_file_uploads int

允许同时上传的最大文件数。提交时留空的上传字段不计入此限制。

General SQL

General SQL Configuration Options
名字 默认 可修改范围 更新日志
sql.safe_mode "0" PHP_INI_SYSTEM Removed as of PHP 7.2.0

这是配置指令的简短说明。

sql.safe_mode bool

If turned on, database connection functions that specify default values will use those values in place of any user-supplied arguments. For details on the default values, see the documentation for the relevant connection functions.

警告

This feature has been REMOVED as of PHP 7.2.0.

Windows Specific

Windows Specific Configuration Options
名字 默认 可修改范围 更新日志
windows.show_crt_warning "0" PHP_INI_ALL  

这是配置指令的简短说明。

windows.show_crt_warning bool

This directive shows the Windows CRT warnings when enabled.

打开 哈希空间 微信小程序中查看更佳