title: PHP Using curl with torcache
body: <p>Hi I want to be able to do the following:</p>
  
  <pre><code>&lt;?php
  
  function get_data($url)
  {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
  }
  $data = get_data('https://torcache.net/torrent/7975CDEEDCEC6092729DAEAE302CB9BD7D633B0B.torrent');
  
  ?&gt;
  </code></pre>
  
  <p>However it seems that torcache is returning a html page and then the torrent is seved a few seconds after, is there anyway for curl to get the actual torrent? At the minute $data just contains the html page torcache returns?</p>
  
  <p>Attempted to set referer as: 
        curl_setopt($ch, CURLOPT_REFERER, 'https://torcache.net/torrent/7975CDEEDCEC6092729DAEAE302CB9BD7D633B0B.torrent');</p>
  
  <p>But not working, I get this response:</p>
  
  <pre><code>&lt;head&gt;&lt;title&gt;302 Found&lt;/title&gt;&lt;/head&gt;
  &lt;body bgcolor="white"&gt;
  &lt;center&gt;&lt;h1&gt;302 Found&lt;/h1&gt;&lt;/center&gt;
  &lt;hr&gt;&lt;center&gt;nginx/1.2.0&lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks</p>
  
  <p>SOLVED:</p>
  
  <pre><code>function get_data($url)
  {
      $ch = curl_init();
      $timeout = 5;
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
      curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch,CURLOPT_REFERER, 'https://torcache.net/');
      curl_setopt($ch,CURLOPT_ENCODING,"gzip");
      $data = curl_exec($ch);
      curl_close($ch);
      return $data;
  }
  </code></pre>
  
  <p>Added "curl_setopt($ch,CURLOPT_ENCODING,"gzip");" this also as the data was gzipped!</p>