title: Google PageSpeed API sometimes return NULL
body: <p>I am using google pagespeed api. But sometimes it simply returns NULL when I call. I am using PHP and CURL to call the api. Below is my code</p>
  
  <pre><code>$url_req = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=' . $url . '&amp;key=' . $myKEY . '&amp;screenshot=true&amp;snapshots=true&amp;strategy=mobile';
  $results = checkPageSpeed($url_req);
  </code></pre>
  
  <p>and below is checkPageSpeed function code</p>
  
  <pre><code>function checkPageSpeed($url) {
  if (function_exists('file_get_contents')) {
      $result = @file_get_contents($url);
  }
  if ($result == '') {
      $ch = curl_init();
      $timeout = 0;
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
      $result = curl_exec($ch);
      curl_close($ch);
  }
  
  return $result;
  }
  </code></pre>
  
  <p>Can anyone help me please.</p>
  
  <p>P.S. It's working fine most of the times but for some urls like those which redirect from www to non www or vice versa it's returning NULL</p>