title: Relationship between php’s memory_limit, upload_max_filesize and post_max_filesize
body: <p><strong>Bottom-line</strong>:<br>
  Do I need to be concerned about setting <em><code>post_max_filesize</code></em> >> <em><code>memory_limit</code></em>?</p>
  
  <p><strong>Details</strong>:<br>
  <a href="https://stackoverflow.com/questions/3651141/in-php-settings-should-memory-limit-upload-max-filesize#answer-3651195">This answer</a> suggests that uploaded files do not need to fit within php’s memory_limit. The <a href="http://php.net/manual/en/ini.core.php#ini.post-max-size" rel="nofollow noreferrer">php docs</a> suggest that the entire post should fit within php’s memory limit. </p>
  
  <p>I find the docs surprising and I’m hoping someone can elaborate. For example take the following php configs:</p>
  
  <pre><code>; config A
  memory_limit = 50M
  upload_max_filesize = 100M
  post_max_filesize = 1000M
  max_file_uploads = 10    
  </code></pre>
  
  <p>and</p>
  
  <pre><code>; config B
  memory_limit = 50M
  upload_max_filesize = 10M
  post_max_filesize = 1000M
  max_file_uploads = 100    
  </code></pre>
  
  <p>With these configurations I’d expect to be able to:
  <ul><li>upload 10x100mb files to server <em>A</em>,</li> <li>and 100x10mb files to server <em>B</em>.</li></ul> I would also expect that:<ul><li> Working with any one of the 10 files uploaded to server <em>A</em> is a problem (100Ms of file in a 50M bag…).</li><li>Working with any 1 of the 100 files uploaded to server <em>B</em> is okay (10 &lt; 50).</li></ul> While experimenting with less round but equivalently related numbers, I’ve found these expectations hold true. </p>
  
  <p>This experience would lead me to say that "generally the memory_limit should be larger than the <em><code>upload_max_filesize</code></em>"; instead, the php <a href="http://php.net/manual/en/ini.core.php#ini.post-max-size" rel="nofollow noreferrer">docs</a> say: </p>
  
  <blockquote>
    <p>generally speaking, memory_limit should be larger than <em><code>post_max_size</code></em>.</p>
  </blockquote>
  
  <p>Why and what happens if it isn't? </p>
  
  <p>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 <em><code>post_max_filesize</code></em> >> <em><code>memory_limit</code></em>?</p>
  
  <p><strong>Aside:</strong><br>
  Violating the manual's rule does not result in a grossly broken server (w/ php5.3 apache2.2 debian 6). </p>