diff --git a/include/image_fetch.php b/include/image_fetch.php index efc79a5..b284c70 100644 --- a/include/image_fetch.php +++ b/include/image_fetch.php @@ -42,15 +42,23 @@ final class ImageFetch /** Fehlercodes, bei denen sich ein Retry lohnt */ private static array $RETRY_HTTP = [429, 500, 502, 503, 504, 520, 521, 522, 523, 524]; - private static array $RETRY_CURL = [ - CURLE_OPERATION_TIMEDOUT, - CURLE_COULDNT_RESOLVE_HOST, - CURLE_COULDNT_CONNECT, - CURLE_RECV_ERROR, - CURLE_SEND_ERROR, - CURLE_GOT_NOTHING, - CURLE_HTTP2_STREAM, // HTTP/2 stream error/RESET - ]; + + private static function retryCurlCodes(): array + { + $list = [ + \defined('CURLE_OPERATION_TIMEDOUT') ? \constant('CURLE_OPERATION_TIMEDOUT') : null, + \defined('CURLE_COULDNT_RESOLVE_HOST') ? \constant('CURLE_COULDNT_RESOLVE_HOST') : null, + \defined('CURLE_COULDNT_CONNECT') ? \constant('CURLE_COULDNT_CONNECT') : null, + \defined('CURLE_RECV_ERROR') ? \constant('CURLE_RECV_ERROR') : null, + \defined('CURLE_SEND_ERROR') ? \constant('CURLE_SEND_ERROR') : null, + \defined('CURLE_GOT_NOTHING') ? \constant('CURLE_GOT_NOTHING') : null, + \defined('CURLE_HTTP2_STREAM') ? \constant('CURLE_HTTP2_STREAM') : null, // nur wenn vorhanden + \defined('CURLE_HTTP2') ? \constant('CURLE_HTTP2') : null, // manche Builds haben nur den + ]; + // Nulls rausfiltern + return array_values(array_filter($list, static fn($v) => $v !== null)); + } + /** Öffentliche API */ public static function download(string $url, array $opt = []): array @@ -172,8 +180,8 @@ final class ImageFetch }, CURLOPT_ACCEPT_ENCODING => '', // gzip/br zulassen ]; - if ($cfg['ip_resolve_v4']) { - $opts[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; + if (!empty($cfg['ip_resolve_v4']) && \defined('CURLOPT_IPRESOLVE') && \defined('CURL_IPRESOLVE_V4')) { + $opts[CURLOPT_IPRESOLVE] = \constant('CURL_IPRESOLVE_V4'); } if ($referer) { $opts[CURLOPT_REFERER] = $referer; @@ -224,7 +232,7 @@ final class ImageFetch // Fehler oder Non-2xx → ggf. retry @unlink($tmp); $doRetry = ($i + 1) < $attempts && - (in_array($http, self::$RETRY_HTTP, true) || in_array($cerr, self::$RETRY_CURL, true) || $http === 0); + (in_array($http, self::$RETRY_HTTP, true) || in_array($cerr, self::retryCurlCodes(), true) || $http === 0); error_log("{$cfg['log_prefix']} fail http=$http curl={$cerr}:{$cerrStr} ua#{$i} retry=".($doRetry?'1':'0')." url=$url"); }