文件上传

;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;;

允许 http 文件上传

; Whether to allow HTTP file uploads. ; http://php.net/file-uploads file_uploads = On

是否支持 http 文件上传。默认为支持

  1. // 关闭 Http 的文件上传
  2. file_uploads = false

文件上传临时路径

; Temporary directory for HTTP uploaded files (will use system default if not ; specified). ; http://php.net/upload-tmp-dir

指定文件上传后保存的临时路径,不指定则使用系统默认路径。配置时需要注意该目录的权限,避免无权限访问的情况。

// 指定文件上传后的临时保存目录, 注意该目录的权限
upload_tmp_dir = /Users/zed/WebServer/Upload

文件上传最大值

; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 2M

限制文件上传的最大值 (仅指文件域, 非整个请求)。

// 限制最大上传文件为5M
upload_max_filesize = 5M

文件上传最大数量

; Maximum number of files that can be uploaded via a single request max_file_uploads = 20

配置单个请求内可以上传文件的最大数量限制。

// 限制单个请求内最多可以上传20个文件
max_file_uploads = 20

数据处理

;;;;;;;;;;;;;;;;; ; Data Handling ; ;;;;;;;;;;;;;;;;;

POST 请求最大值

; Maximum size of POST data that PHP will accept. ; Its value may be 0 to disable the limit. It is ignored if POST data reading ; is disabled through enable_post_data_reading. ; http://php.net/post-max-size post_max_size = 8M

PHP允许接收的 post 请求的数据最大值限制。如果该值设置为0, 则表示禁用大小限制。
如果禁用 post 数据的读取(配置 enable_post_data_reading 参数),该参数将被忽略**

// 不接收超过8M的post请求
post_max_size = 8M

资源限制

;;;;;;;;;;;;;;;;;;; ; Resource Limits ; ;;;;;;;;;;;;;;;;;;;

内存限制

; Maximum amount of memory a script may consume (128MB) ; http://php.net/memory-limit memory_limit = 128M

一个 PHP 脚本可以消耗的最大内存值。默认为128M

// 单个PHP服务最大占用 64M 内存
memory_limit = 64M

模块设置

;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;;

会话模块

[Section]

session 存储媒介

; Handler used to store/retrieve data. ; http://php.net/session.save-handler session.save_handler = files

指定用来存储和恢复数据的媒介(如数据库, 文件)

session 名称

; Name of the session (used as cookie name). ; http://php.net/session.name session.name = PHPSESSID

会话名称,也用作 cookie 名称。(cookie 的值是 session_id)

session 保存路径

; Argument passed to save_handler. In the case of files, this is the path ; where data files are stored. Note: Windows users have to change this ; variable in order to use PHP’s session functions.

传递给 save_handler 的参数. 在本配置文件中, 这是用来存储数据文件的路径。
注意: 为了使用PHP的会话功能, Windows用户必须修改该变量

; The path can be defined as: ; ; session.save_path = “N;/path” ; ; where N is an integer. Instead of storing all the session files in ; /path, what this will do is use subdirectories N-levels deep, and ; store the session data in those directories. This is useful if ; your OS has problems with many files in one directory, and is ; a more efficient layout for servers that handle many sessions.

当N是整数时, 不再是保存所有的会话文件到 /path , 而是将会话数据保存到N层的子目录中.
针对容易在同一目录保存过多文件而出错的操作系统而言非常有用,对于处理大量会话的服务器而言也是更有效的处理方式。

; ; NOTE 1: PHP will not create this directory structure automatically. ; You can use the script in the ext/session dir for that purpose. ; NOTE 2: See the section on garbage collection below if you choose to ; use subdirectories for session storage

注意1:PHP并不会自动创建这些目录结构, 可使用 ext/session 目录中的脚本来处理此事
注意2:如果要使用子目录来存储会话, 请查看后续关于“garbage collection”部分的内容

; The file storage module creates files using mode 600 by default. ; You can change that by using ; ; session.save_path = “N;MODE;/path” ; ; where MODE is the octal representation of the mode. Note that this

; does not overwrite the process’s umask.

; http://php.net/session.save-path

; session.save_path = “/tmp”

文件存储组件默认会使用 600 权限模式来创建文件。可以通过 session.save_path = "N;MODE;/path" 方式进行修改。
MODE 是对应权限模式的8进制表示. 注意此操作并不会覆盖进程的权限

session 自动开始

; Initialize session on request startup. ; http://php.net/session.auto-start session.auto_start = 0

在请求启动时初始化 session (每次访问php文件自动执行 session_start(); )

是否使用 Cookie

; Whether to use cookies. ; http://php.net/session.use-cookies session.use_cookies = 1

配置会话是否要使用 Cookie 技术

仅使用 Cookie

; This option forces PHP to fetch and use a cookie for storing and maintaining

; the session id. We encourage this operation as it’s very helpful in combating

; session hijacking when not specifying and managing your own session id. It is

; not the be-all and end-all of session hijacking defense, but it’s a good start.

; http://php.net/session.use-only-cookies

session.use_only_cookies = 1

该选项强制PHP取得并使用 cookie 来保存和维护 session_id 。在没有指定和管理您自己的 session_id 时,该操作能有效的防止 session 劫持,建议启用。这并不是防御 session 劫持的核心部分,但会是个好的开始。

Cookie 仅 Http 有效

; Whether or not to add the httpOnly flag to the cookie, which makes it inaccessible to browser scripting languages such as JavaScript. ; > http://php.net/session.cookie-httponly session.cookie_httponly = 指定 cookie 仅在 Http 请求时才会生效, 无法被客户端脚本语言如JS等获取

Cookie 仅 Https 有效

; http://php.net/session.cookie-secure

;session.cookie_secure =

配置 session 所使用的 cookie 是否仅在 Https 请求下才会生效

Cookie 有效时间

; Lifetime in seconds of cookie or, if 0, until browser is restarted. ; http://php.net/session.cookie-lifetime session.cookie_lifetime = 0

cookie 的有效时间,单位为秒。如果该值是0, 则浏览器重启时失效

Cookie 生效域名

; The domain for which the cookie is valid. ; http://php.net/session.cookie-domain session.cookie_domain =

指定cookie在哪些域名下会生效

Cookie 生效路径

; The path for which the cookie is valid. ; http://php.net/session.cookie-path session.cookie_path = /

指定cookie在哪些访问路径下会生效

session 垃圾回收

; After this number of seconds, stored data will be seen as ‘garbage’ and

; cleaned up by the garbage collection process.

; http://php.net/session.gc-maxlifetime

session.gc_maxlifetime = 1440

超过该值指定秒数(过期)的存储数据(session文件)会被视为垃圾, 将被垃圾回收机制清除掉