Http timeout retry provider for Laravel
3dgoo/laravel-http-timeout-retry-provider is a Laravel package for http timeout retry provider for laravel.
It currently has 0 GitHub stars and 57 downloads on Packagist (latest version 1.1.2).
Install it with composer require 3dgoo/laravel-http-timeout-retry-provider.
Discover more Laravel packages by 3dgoo
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package that adds retry functionality to Http requests with configurable timeout handling and HTTP method filtering.
withTimeoutRetry() macro to Laravel's HTTP clientConnectionException (timeout) and other configurable exceptionsRequire the package via Composer:
composer require 3dgoo/laravel-http-timeout-retry-provider
The service provider will be auto-discovered by Laravel.
You can publish the configuration file:
php artisan vendor:publish --provider="X3dgoo\HttpTimeoutRetryProvider\Providers\HttpTimeoutRetryProvider" --tag=config
Or, set the following environment variables in your .env file:
HTTP_RETRY_ENABLED=true
HTTP_RETRY_ATTEMPTS=3
HTTP_RETRY_DELAY=100
HTTP_RETRY_ALLOWED_METHODS=GET,HEAD,OPTIONS
HTTP_RETRY_LOGGING_ENABLED=false
HTTP_RETRY_LOGGING_LEVEL=info
HTTP_RETRY_LOGGING_CHANNEL=
Use the withTimeoutRetry() macro on any HTTP client request:
use Illuminate\Support\Facades\Http;
// Will retry GET requests (safe method)
$response = Http::withTimeoutRetry()->get('https://api.example.com/data');
// Will NOT retry POST requests by default (unsafe method)
$response = Http::withTimeoutRetry()->post('https://api.example.com/create', $data);
Override default settings for specific requests:
Http::withTimeoutRetry(
attempts: 5,
delay: 250,
callback: function ($exception) {
return $exception instanceof \RuntimeException;
},
logRetries: true,
allowedMethods: ['POST', 'PUT']
)->post('https://api.example.com/create', $data);
By default, only safe HTTP methods are retried to prevent unintended side effects:
// These methods are retried by default (safe, idempotent):
Http::withTimeoutRetry()->get('https://api.example.com/data');
Http::withTimeoutRetry()->head('https://api.example.com/check');
Http::withTimeoutRetry()->options('https://api.example.com/');
// These methods are NOT retried by default (potentially unsafe):
Http::withTimeoutRetry()->post('https://api.example.com/create');
Http::withTimeoutRetry()->put('https://api.example.com/update');
Http::withTimeoutRetry()->delete('https://api.example.com/item');
When you need to retry unsafe methods, override at runtime:
// Allow specific methods for this request
Http::withTimeoutRetry(
allowedMethods: ['POST', 'PUT']
)->post('https://api.example.com/idempotent-create', $data);
// Allow all methods for this request
Http::withTimeoutRetry(
allowedMethods: ['*']
)->delete('https://api.example.com/resource/123');
Different HTTP methods have different safety characteristics:
// Safe methods only (recommended default)
'allowed_methods' => ['GET', 'HEAD', 'OPTIONS'],
// All read operations
'allowed_methods' => ['GET', 'HEAD', 'OPTIONS'],
// Include idempotent write operations (use with caution)
'allowed_methods' => ['GET', 'HEAD', 'OPTIONS', 'PUT'],
// All methods (not recommended as default)
'allowed_methods' => ['*'],
When logging is enabled, retry attempts are logged with detailed information including the HTTP method:
HTTP_RETRY_LOGGING_LEVEL (default: info)HTTP_RETRY_LOGGING_CHANNEL (uses default log channel if not set)Example log entry:
[2025-06-25 12:00:00] local.info: HTTP GET request retry attempt 1/3 failed for URL https://api.example.com/create: Connection timeout
{
"attempt": 1,
"total_attempts": 3,
"exception_class": "Illuminate\\Http\\Client\\ConnectionException",
"exception_message": "Connection timeout",
"request_url": "https://api.example.com/create",
"request_method": "GET"
}
Default config (config/http.php):
return [
'retry' => [
'enabled' => env('HTTP_RETRY_ENABLED', true),
'attempts' => max(0, min(100, env('HTTP_RETRY_ATTEMPTS', 3))),
'delay' => max(10, env('HTTP_RETRY_DELAY', 100)),
'allowed_methods' => array_map('strtoupper', explode(',', env('HTTP_RETRY_ALLOWED_METHODS', 'GET,HEAD,OPTIONS'))),
'logging' => [
'enabled' => env('HTTP_RETRY_LOGGING_ENABLED', false),
'level' => env('HTTP_RETRY_LOGGING_LEVEL', 'info'),
'channel' => env('HTTP_RETRY_LOGGING_CHANNEL', null),
],
],
];
MIT