This commit is contained in:
pezcurrel 2022-12-16 21:58:06 +01:00
parent d7ffe48214
commit 1bdd59dca7

View file

@ -1,35 +0,0 @@
<?php
function gurl($url,$conntimeout,$timeout=45,$headers=[]) {
$curli=curl_init();
// i 2 qui sotto servono a far sì che ctrl+c sia intercettato a monte
/*curl_setopt($curli,CURLOPT_NOPROGRESS,false);
curl_setopt($curli,CURLOPT_PROGRESSFUNCTION,function($curli,10,10,10,10){});*/
curl_setopt($curli,CURLOPT_URL,$url);
curl_setopt($curli,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curli,CURLOPT_FAILONERROR,true);
curl_setopt($curli,CURLOPT_CONNECTTIMEOUT,$conntimeout);
curl_setopt($curli,CURLOPT_TIMEOUT,$timeout);
curl_setopt($curli,CURLOPT_HTTPHEADER,$headers);
curl_setopt($curli,CURLOPT_HEADER,true);
curl_setopt($curli,CURLOPT_ENCODING,'');
$cont=curl_exec($curli);
$headers_sz=curl_getinfo($curli,CURLINFO_HEADER_SIZE);
$headers=strtolower(substr($cont,0,$headers_sz));
$cont=substr($cont,$headers_sz);
$emsg=false;
$cerrno=curl_errno($curli);
if ($cerrno>0) {
$emsg=$cerrno;
$cerrmsg=trim(curl_error($curli));
if ($cerrmsg!='') $emsg.=': '.$cerrmsg;
$cont=false;
} elseif (!$cont) {
$cont=false;
$emsg='unknown';
}
curl_close($curli);
return(['cont'=>$cont,'headers'=>$headers,'emsg'=>$emsg]);
}
?>