title: Using cURL to download images to ZipArchive
body: <p>I'm trying to download images to a ZipArchive, from a social networking site via their API, I'm using the following code:</p>
  
  <pre><code>...
  public function downloadAlbumZip($album_name, $photos)
  {
      $zip = new ZipArchive();
      $album_name = $this-&gt;_cleanAlbumName($album_name);
      $filename = 'album.zip';
      $file = tempnam(PHOTOS, "{$album_name}-").'.zip';
  
      if ($zip-&gt;open($file, ZIPARCHIVE::CREATE) === TRUE)
      {
          foreach ($photos as $photo) {
              $image = $photo['pid'] . '.jpg';
              $binary = $this-&gt;_getImage($photo['src']);
              $zip-&gt;addFromString($image, $binary);
          }
  
          $output = print_r($zip, true);
          $zip-&gt;close();
  
          exit('Zip Saved.&lt;br /&gt;&lt;a href="javascript:history.go(-1);"&gt;Back to Album Overview&lt;/a&gt;');
      } else {
          die('Zip Failed.');
      }
  }
  
  private function _getImage($img)
  {
      if ( function_exists('curl_init') )
      {
          $ch = curl_init($img);
  
          curl_setopt($ch, CURLOPT_HEADER, 0);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  
          $rawdata = curl_exec($ch);
          curl_close($ch);
  
          return $rawdata;
      }
  }
  ...
  </code></pre>
  
  <p>Which works but is very slow and often ends in a timeout error, can anyone recommend a way to speed this up?</p>
  
  <p>Thanks</p>