Bottom-line:
Do I need to be concerned about setting post_max_filesize
>> memory_limit
?
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.
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
and
; config B
memory_limit = 50M
upload_max_filesize = 10M
post_max_filesize = 1000M
max_file_uploads = 100
With these configurations I’d expect to be able to:
- upload 10x100mb files to server A,
- and 100x10mb files to server B.
I would also expect that:
- 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).
While experimenting with less round but equivalently related numbers, I’ve found these expectations hold true.
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:
generally speaking, memory_limit should be larger than post_max_size
.
Why and what happens if it isn't?
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
?
Aside:
Violating the manual's rule does not result in a grossly broken server (w/ php5.3 apache2.2 debian 6).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…