title: PHP File upload - memory handling on CGI
body: <p>I'm wondering how PHP handles a file upload. I'v <a href="http://www.php.net/manual/en/features.file-upload.php#78017" rel="nofollow">read</a> a file upload will be split in chunks and will be assembled after the upload has finished. Is there any verification of this fact? This will help to understand the handling and settings for a file upload.
  Is the handling of mod_php or CGI the same? mod_php is more tied together with Apache. CGI has to read a stream and then do it's magic.</p>
  
  <p>How is the memory involved in this process.</p>
  
  <p>Is this correct?</p>
  
  <ol>
  <li>Apache handles <a href="http://www.faqs.org/rfcs/rfc1867.html" rel="nofollow">HTTP request</a></li>
  <li>Apache calls PHP over CGI and streams data (pipe)</li>
  <li>PHP splits input in chunks of a certain size to not reach the memory limit</li>
  <li>Stream end is found</li>
  <li>PHP assembles split files into one file and will delete the split files</li>
  <li>Information about file upload will be save into $_FILES</li>
  </ol>