title: PHP download and extract zip file
body: <p>I have the following code that downloads a zip file from an external source and then extracts it:</p>
  
  <pre><code>file_put_contents("my-zip.zip", fopen("http://www.externalsite.com/zipfile.zip", 'r'));
  
  $zip = new ZipArchive;
  $res = $zip-&gt;open('my-zip.zip');
  if ($res === TRUE) {
    $zip-&gt;extractTo('/extract-here');
    $zip-&gt;close();
    //
  } else {
    //
  }
  </code></pre>
  
  <p>This works fine, however my question is, does the unzipping procedure wait until the file_put_contents function is complete? Or will it try and run half way through?</p>
  
  <p>It seems to work fine right now but I'm thinking that if the zip file download is delayed or slow for whatever reason that it may crash why trying to unzip a file that doesn't exist.</p>
  
  <p>If that makes sense.</p>