Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Google PageSpeed API有时返回空值_Php_Curl_Google Api_Google Pagespeed - Fatal编程技术网

Php Google PageSpeed 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

我正在使用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 = 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