修改php.ini 中 默认设置 一般是-1
default_socket_timeout = 360
请求不了数据 ,抓取https的数据
function getRealUrl($url){
stream_context_set_default( [
'ssl' => [
'verify_host' => false,
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$header = get_headers($url,1);
if (strpos($header[0],'301') || strpos($header[0],'302')) {
if(is_array($header['Location'])) {
return $header['Location'][count($header['Location'])-1];
}else{
return $header['Location'];
}
}else {
return $url;
}
}
来源:oschina
链接:https://my.oschina.net/hongjiang/blog/3196579