title: PHP - Safe way to download large files?
body: <p><strong>Information</strong></p>
  
  <p>There are many ways to download files in PHP, <a href="http://php.net/manual/en/function.file-get-contents.php" rel="nofollow">file_get_contents</a> + <a href="http://php.net/manual/en/function.file-put-contents.php" rel="nofollow">file_put_contents</a>, <a href="http://php.net/manual/en/function.fopen.php" rel="nofollow">fopen</a>, <a href="http://php.net/manual/en/function.readfile.php" rel="nofollow">readfile</a> and cURL.</p>
  
  <p><strong>Question?</strong></p>
  
  <ul>
  <li>When having a large file, let's say 500 MB from another server / domain, what is the "correct" way to downloaded it safe? If connection failes it should find the position and continue OR download the file again if it contains errors.</li>
  <li>It's going to be used on a web site, not in php.exe shell.</li>
  </ul>
  
  <p><strong>What I figured out so far</strong></p>
  
  <ul>
  <li>I've read about AJAX solutions with progress bars but what I'm really looking for is a PHP solution.</li>
  <li>I don't need to buffer the file to a string like file_get_contents does. That probably uses memory as well.</li>
  <li>I've also read about memory problems. A solution that don't use that much memory might be prefered.</li>
  </ul>
  
  <p><strong>Concept</strong></p>
  
  <p>This is sort of what I want if the result is false.</p>
  
  <pre><code>function download_url( $url, $filename ) {
      // Code
      $success['success'] = false;
      $success['message'] = 'File not found';
      return $success;
  }
  </code></pre>