36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
<?php
|
|
|
|
function curlprogress($curli,$dlsz=0,$dled=0,$ulsz=0,$uled=0) {
|
|
// echo "DL: ${dled}; UL: ${uled}\n";
|
|
}
|
|
|
|
function gurl($url,$conntimeout=5,$functimeout=10,$headers=[]) {
|
|
$curli=curl_init();
|
|
/* curl_setopt($curli,CURLOPT_NOPROGRESS,false);
|
|
curl_setopt($curli,CURLOPT_PROGRESSFUNCTION,'curlprogress');*/
|
|
curl_setopt($curli,CURLOPT_URL,$url);
|
|
curl_setopt($curli,CURLOPT_RETURNTRANSFER,true);
|
|
curl_setopt($curli,CURLOPT_FAILONERROR,true);
|
|
curl_setopt($curli,CURLOPT_CONNECTTIMEOUT,$conntimeout+0);
|
|
curl_setopt($curli,CURLOPT_TIMEOUT,$functimeout+0);
|
|
curl_setopt($curli,CURLOPT_HTTPHEADER,$headers);
|
|
curl_setopt($curli,CURLOPT_HEADER,true);
|
|
curl_setopt($curli,CURLOPT_ENCODING,'');
|
|
curl_setopt($curli,CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0');
|
|
$gheaders='';
|
|
$ecode=false;
|
|
$emsg=false;
|
|
$cont=curl_exec($curli);
|
|
if ($cont!==false) {
|
|
$gheaders_sz=curl_getinfo($curli,CURLINFO_HEADER_SIZE);
|
|
$gheaders=strtolower(substr($cont,0,$gheaders_sz));
|
|
$cont=substr($cont,$gheaders_sz);
|
|
} else {
|
|
$ecode=curl_errno($curli);
|
|
$emsg=$ecode.': '.trim(curl_error($curli));
|
|
}
|
|
curl_close($curli);
|
|
return(['cont'=>$cont,'headers'=>$gheaders,'ecode'=>$ecode,'emsg'=>$emsg]);
|
|
}
|
|
|
|
?>
|