true, CURLOPT_HTTPHEADER => [ 'Accept: application/json', ], CURLOPT_CONNECTTIMEOUT => 3, CURLOPT_TIMEOUT => 10, ]); $body = curl_exec($curl); $errno = curl_errno($curl); $error = curl_error($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($body === false) { $lastError = "cURL error {$errno}: {$error}"; echo "Attempt {$attempt}: {$lastError}" . PHP_EOL; $shouldRetry = in_array($errno, $retryCurlErrors, true); } else { echo "Attempt {$attempt}: HTTP {$status}" . PHP_EOL; if ($status >= 200 && $status < 300) { echo "Response body: " . trim($body) . PHP_EOL; exit(0); } $lastError = "HTTP {$status}: " . trim($body); $shouldRetry = in_array($status, $retryStatuses, true); } if (!$shouldRetry || $attempt === $maxAttempts) { break; } $delay = $baseDelaySeconds * (2 ** ($attempt - 1)); echo "Retrying after {$delay} seconds." . PHP_EOL; usleep((int) ($delay * 1000000)); } echo "Request failed after {$maxAttempts} attempts." . PHP_EOL; echo "Last error: {$lastError}" . PHP_EOL; exit(1);