php的memory_limit、upload_max_filesize和post_max_filesize的关系 [英] Relationship between php’s memory_limit, upload_max_filesize and post_max_filesize
问题描述
底线:
我需要关心设置 post_max_filesize
>> memory_limit
吗?
详细信息:
这个答案表明上传的文件不需要适合 php 的 memory_limit.php 文档 建议整个帖子应该适合 php 的内存限制.
Details:
This answer suggests that uploaded files do not need to fit within php’s memory_limit. The php docs suggest that the entire post should fit within php’s memory limit.
我发现文档令人惊讶,我希望有人能详细说明.例如采用以下 php 配置:
I find the docs surprising and I’m hoping someone can elaborate. For example take the following php configs:
; config A
memory_limit = 50M
upload_max_filesize = 100M
post_max_filesize = 1000M
max_file_uploads = 10
和
; config B
memory_limit = 50M
upload_max_filesize = 10M
post_max_filesize = 1000M
max_file_uploads = 100
通过这些配置,我希望能够:
- 上传 10x100mb 文件到服务器 A,
- 上传 100x10mb 文件到服务器 B.
- upload 10x100mb files to server A,
- and 100x10mb files to server B.
- 处理上传到服务器 A 的 10 个文件中的任何一个都是一个问题(50M 包中有 100M 的文件......).
- 使用上传到服务器 B 的 100 个文件中的任何一个都可以(10 <50 个).
- Working with any one of the 10 files uploaded to server A is a problem (100Ms of file in a 50M bag…).
- Working with any 1 of the 100 files uploaded to server B is okay (10 < 50).
With these configurations I’d expect to be able to:
这个经验会让我说通常memory_limit应该大于upload_max_filesize
";相反,php docs 说:
This experience would lead me to say that "generally the memory_limit should be larger than the upload_max_filesize
"; instead, the php docs say:
一般来说,memory_limit 应该大于post_max_size
.
generally speaking, memory_limit should be larger than
post_max_size
.
为什么,如果不是,会发生什么?
Why and what happens if it isn't?
当我的 php 代码被执行时,我没有看到所有发布的文件都在内存中的证据.在我看来,我所拥有的只是一个 $_FILES 数组,其中包含专门在磁盘上找到的文件的路径.在我内省环境之前的某个时间点,php 是否将整个帖子保存在内存中?我需要关心设置 post_max_filesize
>> memory_limit
吗?
When my php code is executed I see no evidence that all of the posted files are in memory. It seems to me that all I’ve got is a $_FILES array of paths to files found exclusively on disk. Is php holding the whole post in memory at some point prior to my ability to introspect the environment? Do I need to be concerned about setting post_max_filesize
>> memory_limit
?
旁白:
违反手册规则不会导致服务器严重损坏(使用 php5.3 apache2.2 debian 6).
Aside:
Violating the manual's rule does not result in a grossly broken server (w/ php5.3 apache2.2 debian 6).
推荐答案
PHP 将接受单个小于 upload_max_filesize
且合计小于 post_max_size
字节的上传文件.PHP 文档关于 memory_limit
是错误的,它不需要保存发布的文件内容.
PHP will accept uploaded files that are individually smaller than upload_max_filesize
and together take less than post_max_size
bytes. The PHP documentation is wrong with regard to memory_limit
which does not need to hold the file contents posted.
以下配置适用于 Apache2 模块和 CGI,并接受小于 1G 的文件.
The following configuration works with both Apache2 module and CGI, and accepts files smaller than 1G.
upload_max_filesize = 1G
post_max_size = 1G
memory_limit = 32M
这篇关于php的memory_limit、upload_max_filesize和post_max_filesize的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!