title: Downloading a large file using curl
body: <p>I need to download remote file using curl.</p>
  
  <p>Here's the sample code I have:</p>
  
  <pre><code>$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
  $st = curl_exec($ch);
  $fd = fopen($tmp_name, 'w');
  fwrite($fd, $st);
  fclose($fd);
  
  curl_close($ch);
  </code></pre>
  
  <p>But it can't handle big files, because it reads to memory first.</p>
  
  <p>Is it possible to stream the file directly to disk?</p>