title: Curl, file_get_contents and Instagram's CDN
body: <p>After two days of research I didn't manage to find the answer/solution to my question/problem. So, here I am. Pardon me if it's already posted somewhere, I would appreciate the link. So...</p>
  
  <p>I have an app that fetches instagram content/images based on hashtags. I need to copy the selected images from the instagram cdn (imageurl) to my server. </p>
  
  <p>The application used to work smooth until recently... the problem lies within:</p>
  
  <pre><code>$img = "https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s320x320/e35/11848968_1650345541876481_204433741_n.jpg"
  imagecreatefromjpeg($img);
  </code></pre>
  
  <p>The error output is: failed to open stream - SSL connection timeout</p>
  
  <p>If is use
  "<a href="http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_7.jpg" rel="nofollow">http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_7.jpg</a>" as url, there is no problem. </p>
  
  <p>I've also tried other solutions, like using curl:</p>
  
  <pre><code>function getSSLPage($url) {
  $ch = curl_init();
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // tried true/false
  curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false); // tried true/false
  //curl_setopt($ch, CURLOPT_SSLVERSION,1); tried 1,2,3
  
  $retorno['arquivo'] = curl_exec($ch); 
  $retorno['status'] = curl_getinfo($ch);
  $retorno['error']  = curl_error($ch);
  
  curl_close($ch);
  return $retorno;
  }
  var_dump(getSSLPage("https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/e35/11950482_1505223163123401_2062846740_n.jpg"));
  </code></pre>
  
  <p>The same thing happens with both urls, scontent.cdinstragram returns failed to open stream and the amazon url works fine. </p>
  
  <p>The other method I tried:</p>
  
  <pre><code>function img_create($filename, $mime_type) 
  {  
    $content = file_get_contents($filename);
    $base64   = base64_encode($content); 
    return ('data:' . $mime_type . ';base64,' . $base64);
   }
  ?&gt;&lt;img src="&lt;?php print img_create('http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_7.jpg','jpeg'); ?&gt;" alt="random logo" /&gt;
  </code></pre>
  
  <p>Same thing, works for <em>distillery.s3.amazonaws.com</em> and doesnt work for <em>scontent.cdninstagram.com</em></p>
  
  <p>I know getting an image via php must be disabled in the scontent server, but if so, how can I possible get those images?</p>
  
  <p>I've tried authenticating and listing the user's image with users/userid/media_id and providing an access token so I would get the amazonaws url but still I got scontent.cdninstagram imageurls =/</p>
  
  <p>THANKS A LOT!</p>