added fileGetContents

This commit is contained in:
tracer 2022-10-08 10:53:31 +02:00
parent f66298842a
commit 2e1f1ac8b1
1 changed files with 130 additions and 98 deletions

View File

@ -7,7 +7,6 @@ use UnhandledMatchError;
error_reporting(error_level: E_ALL);
/**
*
*/
@ -111,4 +110,37 @@ class ApiController
];
}
function fileGetContents(string $url, int $versionIP): ?array
{
$curl = curl_init(url: $url);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10,
);
if ($versionIP == 4) {
curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V4);
} else {
curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V6);
}
curl_setopt_array(handle: $curl, options: $options);
$content = curl_exec(handle: $curl);
$error = curl_errno(handle: $curl);
$errorMessage = curl_error(handle: $curl);
$header = curl_getinfo(handle: $curl);
curl_close(handle: $curl);
$header['error'] = $error;
$header['errorMessage'] = $errorMessage;
$header['content'] = $content;
return $header;
}
}