35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
|
|
function getfc($url,$timeout,$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_TIMEOUT,30);
|
|
curl_setopt($curli,CURLOPT_CONNECTTIMEOUT,$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]);
|
|
}
|
|
|
|
?>
|