Php Google PageSpeed API有时返回空值
我正在使用google pagespeed api。但有时当我调用时,它只返回NULL。我使用PHP和CURL来调用api。下面是我的代码Php Google PageSpeed API有时返回空值,php,curl,google-api,google-pagespeed,Php,Curl,Google Api,Google Pagespeed,我正在使用google pagespeed api。但有时当我调用时,它只返回NULL。我使用PHP和CURL来调用api。下面是我的代码 $url_req = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=' . $url . '&key=' . $myKEY . '&screenshot=true&snapshots=true&strategy=mobile'; $results
$url_req = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=' . $url . '&key=' . $myKEY . '&screenshot=true&snapshots=true&strategy=mobile';
$results = checkPageSpeed($url_req);
下面是checkPageSpeed功能代码
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;
}
谁能帮帮我吗
另外,它在大多数情况下工作正常,但是对于一些URL,比如从www重定向到非www的URL,或者反之亦然,它返回NULL