Home  >  Article  >  Backend Development  >  Detailed explanation of common configurations in php.ini

Detailed explanation of common configurations in php.ini

小云云
小云云Original
2018-03-31 11:00:1110378browse

This article mainly shares with you the detailed explanation of common configurations in php.ini, mainly in the form of text and code, hoping to help everyone.

Resource Limit

max_execution_time integer
  • This sets the maximum execution time, in seconds, allowed before the script is aborted by the parser. This helps prevent poorly written scripts from hogging server resources. The default setting is 30. When running PHP from the command line, the default setting is 0.

  • max_execution_time Only affects the running time of the script itself. Any other time spent outside the running of the script, such as calls to the system using the function system(), use of the sleep() function, database queries, file uploads, etc., are not included in the calculation The maximum time the script runs is not included.

  • The maximum execution time will not affect system calls and system operations. In safe mode you cannot modify this setting via ini_set(). The only solution is to turn off safe mode or modify the time limit in php.ini.

max_input_time integer

The maximum time allowed for the script to parse input data (similar to POST and GET), in seconds. It starts from receiving all data to starting to execute the script for measurement.

memory_limit integer

Maximum amount of memory a script may consume (default 128MB)

Data processing

post_max_size intager

allowed POSTMaximum byte length of data. This setting also affects file uploads. If the POST data exceeds the limit, then $_POST and $_FILES will be empty. To upload large files, this value must be greater than the value of the upload_max_filesize directive. If memory limit is enabled, this value should be less than the value of the memory_limit directive.

Path settings

include_path string

Specify a set of directories for require(), include(), fopen_with_path() functions to find files. The format is similar to the system's PATH environment variable (separated by colons under UNIX and separated by semicolons under Windows): UNIX: "/path1:/path2", Windows: "\path1;\path2". Use '.' in the include path to allow relative paths, which represent the current directory.

extension_dir string

The directory where extension libraries (modules) are stored is the directory used by PHP to find dynamic extension modules.

File upload

file_uploads boolean or integer

Whether HTTP file upload is allowed. The default value is On to allow HTTP file uploads. This option cannot be set to Off.

upload_tmp_dir string

The temporary directory where files are stored when uploading files (must be a directory writable by the PHP process user). If not specified PHP uses the system default temporary directory.

upload_max_filesize integer

The maximum size of files allowed to be uploaded.

max_file_uploads integer

The maximum number of files allowed to be uploaded simultaneously. As of PHP 5.3.4, upload fields left blank on submission do not count against this limit.

Fopen Encapsulation

allow_url_fopen boolean

This option activates the fopen encapsulation protocol of URL form making it possible to access URL objects such as files . The default encapsulation protocols provide ftp and http protocols to access remote files. Some extension libraries such as zlib may register more encapsulation protocols.

  • #Note: For security reasons, this option can only be set in php.ini.

allow_url_include boolean

This option allows the following functions to be encapsulated using URL-aware fopen: include, include, include_once, require, require_once. This setting requires the allow_url_fopen option to be enable.

default_socket_timeout integer

Default timeout in seconds for socket-based streams.

Date

date.timezone string

Define the default time zone used by date functions

session

session.use_strict_mode boolean

session.use_strict_modeSpecifies whether the module will use strict session ID mode. If this mode is enabled, the module does not accept uninitialized session IDs. If an uninitialized session ID is sent from the browser, a new session ID will be sent to the browser. Applications protect session pinning through strict mode session adoption. Default is 0 (disabled).

session.use_cookies boolean

session.use_cookies Specifies whether to use cookie on the client to store the session ID. Default is 1 (enabled).

session.cookie_secure boolean

session.cookie_secure Specifies whether cookies are only sent over secure connections . Default is off.

session.use_only_cookies boolean

session.use_only_cookies Specifies whether to only use cookie on the client to store the session ID. Enabling this setting prevents attacks involving session IDs being passed through URLs. This setting was added in PHP 4.3.0. As of PHP 5.3.0, the default has been changed to 1 (enabled)

session.name string

session.name 指定会话名以用做 cookie 的名字。只能由字母数字组成,默认为 PHPSESSID

session.auto_start boolean

session.auto_start 指定会话模块是否在请求开始时自动启动一个会话。默认为 0(不启动)

session.serialize_handler string

session.serialize_handler 定义用来序列化/解序列化的处理器名字。 当前支持 PHP 序列化格式 (名为php_serialize)、 PHP PHP 内部格式 (名为 php 及 php_binary) 和 WDDX (名为 wddx)。 如果 PHP 编译时加入了 WDDX 支持,则只能用 WDDX。 自 PHP 5.5.4 起可以使用 php_serialize。php_serialize 在内部简单地直接使用 serialize/unserialize 函数,并且不会有 php 和 php_binary 所具有的限制。 使用较旧的序列化处理器导致 $_SESSION 的索引既不能是数字也不能包含特殊字符(| and !)。 使用 php_serialize 避免脚本退出时,数字及特殊字符索引导致出错。 默认使用 php

session.gc_probability integer

session.gc_probabilitysession.gc_pisor 合起来用来管理 gc(garbag  collection 垃圾回收)进程启动的概率。默认为 1

session.gc_pisor integer

session.gc_pisorsession.gc_probability 合起来定义了在每个会话初始化时启动gc(garbage collection 垃圾回收)进程的概率。此概率用 gc_probability/gc_pisor计算得来。例如 1/100 意味着在每个请求中有 1% 的概率启动 gc 进程。 将此值增加到1000会给你0.1%的几率gc将运行任何给出的请求。 对于大批量生产服务器,这是一个更有效的方法。

session.gc_maxlifetime integer

session.gc_maxlifetime integer 指定过了多少秒之后数据就会被视为“垃圾”并被清除。 垃圾搜集可能会在session 启动的时候开始( 取决于session.gc_probabilitysession.gc_pisor)。

  • Note:如果不同的脚本具有不同的 session.gc_maxlifetime数值但是共享了同一个地方存储会话数据,则具有最小数值的脚本会清理数据。此情况下,与 session.save_path 一起使用本指令。


详情请参考:http://www.cnblogs.com/cuchadanfan/p/6163970.html

资源限制

max_execution_time integer
  • 这设置了脚本被解析器中止之前允许的最大执行时间,单位秒。 这有助于防止写得不好的脚本占尽服务器资源。 默认设置为 30。 从命令行运行 PHP 时,默认设置为 0

  • max_execution_time 仅仅只影响脚本本身运行的时间。任何其它花费在脚本运行之外的时间,诸如用函数 system() 对系统的调用、sleep() 函数的使用、数据库查询、文件上传等,在计算脚本运行的最大时间时都不包括在内。

  • 最大执行时间不会影响系统调用和系统操作等。在 安全模式 下你不能通过 ini_set() 来修改此设置。唯一的解决方法是关闭安全模式或者在 php.ini 中修改时间限制。

max_input_time integer

脚本解析输入数据(类似 POST 和 GET)允许的最大时间,单位是秒。 它从接收所有数据到开始执行脚本进行测量的。

memory_limit integer

脚本可能消耗的最大内存量(默认 128MB)

数据处理

post_max_size intager

允许的POST数据最大字节长度。此设定也影响到文件上传。如果POST数据超出限制,那么$_POST$_FILES将会为空。要上传大文件,该值必须大于upload_max_filesize指令的值。如果启用了内存限制,那么该值应当小于memory_limit指令的值。

路径设置

include_path string

指定一组目录用于require(), include(), fopen_with_path()函数寻找文件。格式和系统的PATH环境变量类似(UNIX下用冒号分隔,Windows下用分号分隔):UNIX: "/path1:/path2",Windows: "\path1;\path2"。在包含路径中使用’.’可以允许相对路径,它代表当前目录。

extension_dir string

存放扩展库(模块)的目录,也就是PHP用来寻找动态扩展模块的目录。

文件上传

file_uploads boolean or integer

是否允许HTTP文件上传。默认值为On允许HTTP文件上传,此选项不能设置为Off。

upload_tmp_dir string

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

upload_max_filesize integer

允许上传的文件的最大尺寸。

max_file_uploads integer

允许同时上传的文件的最大数量。 从PHP 5.3.4开始,上传字段在提交时保持空白不计入此限制。

Fopen 封装

allow_url_fopen boolean

本选项激活了 URL 形式fopen 封装协议使得可以访问 URL 对象例如文件。默认的封装协议提供用 ftp 和 http协议来访问远程文件,一些扩展库例如 zlib 可能会注册更多的封装协议。

  • Note:出于安全性考虑,此选项只能在 php.ini 中设置。

allow_url_include boolean

此选项允许有以下功能使用URL识别的fopen封装:包括,include,include_once,require,require_once。此设置要求allow_url_fopen选项要开启

default_socket_timeout integer

基于 socket 的流的默认超时时间(秒)。

日期

date.timezone string

定义日期函数使用的默认时区

session

session.use_strict_mode boolean

session.use_strict_mode指定模块是否将使用严格的会话ID模式。 如果启用此模式,模块不接受未初始化的会话ID。 如果从浏览器发送未初始化的会话ID,则会将新的会话ID发送到浏览器。 应用程序通过严格模式的会话采用保护会话固定。 默认为0(禁用)。

session.use_cookies boolean

session.use_cookies 指定是否在客户端用 cookie 来存放会话 ID。默认为 1(启用)。

session.cookie_secure boolean

session.cookie_secure 指定是否仅通过安全连接发送 cookie。默认为 off

session.use_only_cookies boolean

session.use_only_cookies 指定是否在客户端仅仅使用 cookie 来存放会话 ID。启用此设定可以防止有关通过 URL 传递会话 ID 的攻击。此设定是 PHP 4.3.0 添加的。自PHP 5.3.0开始,默认值改为1(启用)

session.name string

session.name 指定会话名以用做 cookie 的名字。只能由字母数字组成,默认为 PHPSESSID

session.auto_start boolean

session.auto_start 指定会话模块是否在请求开始时自动启动一个会话。默认为 0(不启动)

session.serialize_handler string

session.serialize_handler 定义用来序列化/解序列化的处理器名字。 当前支持 PHP 序列化格式 (名为php_serialize)、 PHP PHP 内部格式 (名为 php 及 php_binary) 和 WDDX (名为 wddx)。 如果 PHP 编译时加入了 WDDX 支持,则只能用 WDDX。 自 PHP 5.5.4 起可以使用 php_serialize。php_serialize 在内部简单地直接使用 serialize/unserialize 函数,并且不会有 php 和 php_binary 所具有的限制。 使用较旧的序列化处理器导致 $_SESSION 的索引既不能是数字也不能包含特殊字符(| and !)。 使用 php_serialize 避免脚本退出时,数字及特殊字符索引导致出错。 默认使用 php

session.gc_probability integer

session.gc_probabilitysession.gc_pisor 合起来用来管理 gc(garbag  collection 垃圾回收)进程启动的概率。默认为 1

session.gc_pisor integer

session.gc_pisorsession.gc_probability 合起来定义了在每个会话初始化时启动gc(garbage collection 垃圾回收)进程的概率。此概率用 gc_probability/gc_pisor计算得来。例如 1/100 意味着在每个请求中有 1% 的概率启动 gc 进程。 将此值增加到1000会给你0.1%的几率gc将运行任何给出的请求。 对于大批量生产服务器,这是一个更有效的方法。

session.gc_maxlifetime integer

session.gc_maxlifetime integer 指定过了多少秒之后数据就会被视为“垃圾”并被清除。 垃圾搜集可能会在session 启动的时候开始( 取决于session.gc_probabilitysession.gc_pisor)。

  • Note: If different scripts have different session.gc_maxlifetime values ​​but share the same place to store session data, the script with the smallest value will clean up the data . In this case, use this directive together with session.save_path.


The above is the detailed content of Detailed explanation of common configurations in php.ini. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn