title: php curl abrupt behavior
body: <p>I am using php curl to fetch data from youtube. There are two curls. First curl executes successfully and retrieves the access token from youtube. 2nd curl uses this oauth token and retrieves the user info. But it shows unexpected behavior. sometimes it works absolutely fine but oftentimes it shows the error message <code>SSL Connection Timeout</code>. </p>
  
  <p>If there is problem in code then why it works sometime
  The code is </p>
  
  <pre><code>$url_userInfo =  'https://gdata.youtube.com/feeds/api/users/default?access_token='.$_SESSION['yt_access_token'].'&amp;v=2&amp;alt=json';    
  $curl = curl_init();
  $header[0] = "Accept: text/xml,application/xml,application/json, text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  $header[] = "Cache-Control: max-age=0";
  $header[] = "Connection: keep-alive";
  $header[] = "Keep-Alive: 300";
  $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
  $header[] = "Accept-Language: en-us,en;q=0.5";
  $header[] = "Pragma: ";
  
  
  curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
  
  curl_setopt($curl, CURLOPT_HTTPHEADER, $header); 
  curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com');
  curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
  curl_setopt($curl, CURLOPT_AUTOREFERER, false);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl, CURLOPT_URL, $url_userInfo);
  
  curl_setopt($curl, CURLOPT_TIMEOUT, 20);
  
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); //needed for SSL
  
  $content = curl_exec($curl);
  echo curl_error($curl);
  curl_close($curl);
  $res = json_decode($content);
  
  print_r($res);
  </code></pre>