MastodonHelp/web/site/mustard/include/getfc.php

36 lines
1.1 KiB
PHP
Raw Normal View History

2020-09-28 18:40:58 +02:00
<?php
function getfc($url,$conntimeout,$timeout=45,$headers=[]) {
2020-09-28 18:40:58 +02:00
$curli=curl_init();
2020-10-13 08:21:26 +02:00
// 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){});*/
2020-09-28 18:40:58 +02:00
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);
2022-12-08 00:08:36 +01:00
curl_setopt($curli,CURLOPT_HEADER,true);
curl_setopt($curli,CURLOPT_ENCODING,'');
2020-09-28 18:40:58 +02:00
$cont=curl_exec($curli);
2022-12-08 00:08:36 +01:00
$headers_sz=curl_getinfo($curli,CURLINFO_HEADER_SIZE);
$headers=strtolower(substr($cont,0,$headers_sz));
2022-12-08 00:08:36 +01:00
$cont=substr($cont,$headers_sz);
2020-09-28 18:40:58 +02:00
$emsg=false;
$cerrno=curl_errno($curli);
if ($cerrno>0) {
2020-09-28 18:40:58 +02:00
$emsg=$cerrno;
2020-09-28 18:59:18 +02:00
$cerrmsg=trim(curl_error($curli));
2020-09-28 18:40:58 +02:00
if ($cerrmsg!='') $emsg.=': '.$cerrmsg;
$cont=false;
} elseif (!$cont) {
$cont=false;
$emsg='unknown';
}
curl_close($curli);
2022-12-08 00:08:36 +01:00
return(['cont'=>$cont,'headers'=>$headers,'emsg'=>$emsg]);
2020-09-28 18:40:58 +02:00
}
?>