Compare commits

..

No commits in common. "a06a6ed41d5cba413c7d64ffdf1e5a6918df99a3" and "63d6154d40679eef35cb04c4025a3cd12d198de0" have entirely different histories.

View File

@ -237,7 +237,7 @@ final class MD_STD {
* @param string $url URL to query.
* @param integer $timeout Timeout in milliseconds.
*
* @return CurlHandle
* @return resource
*/
public static function curl_init(string $url, int $timeout) {
@ -300,7 +300,9 @@ final class MD_STD {
*/
public static function runCurlMulti(array $urls, int $timeout = 1200):array {
$mh = curl_multi_init();
if (!($mh = curl_multi_init())) {
throw new Exception("Failed to set up multi handle");
}
$curl_array = [];
foreach($urls as $i => $url) {
@ -320,7 +322,7 @@ final class MD_STD {
$res = [];
foreach($urls as $i => $url) {
$res[$i] = curl_multi_getcontent($curl_array[$i]) ?: '';
$res[$i] = curl_multi_getcontent($curl_array[$i]);
}
foreach($urls as $i => $url){
@ -506,6 +508,9 @@ final class MD_STD {
public static function openssl_random_pseudo_bytes(int $length):string {
$output = \openssl_random_pseudo_bytes($length);
if ($output === false) {
throw new Exception("Failed generating random pseudo bytes using openssl_random_pseudo_bytes");
}
return $output;
}
@ -571,36 +576,6 @@ final class MD_STD {
}
/**
* Wrapper around the finfo functions to get the mime content type of a file.
*
* @param string $url Expected file path.
*
* @return string
*/
public static function remote_mime_content_type(string $url):string {
if (($tmp_file = \tempnam(\sys_get_temp_dir(), "remote_mime_type_check")) === false) {
throw new Exception("Failed to get temporary file location");
}
$fp = \fopen($tmp_file, 'w');
if (!($ch = \curl_init($url))) {
throw new Exception("Failed to initialize curl for $url");
};
\curl_setopt($ch, CURLOPT_FILE, $fp);
\curl_exec($ch);
\curl_close($ch);
$mime_type = MD_STD::mime_content_type($tmp_file);
\unlink($tmp_file);
return $mime_type;
}
/**
* Checks if a file exists, with one of the expected mime types.
*