3dgoo / laravel-http-timeout-retry-provider
Http timeout retry provider for Laravel
Requires
- php: ^8.1
- illuminate/http: ^10.0 || ^11.0 || ^12.0
Requires (Dev)
- laravel/pint: ^1.22
- nunomaduro/collision: ^7.10
- orchestra/testbench: ^8.15
- overtrue/phplint: ^9.0
- pestphp/pest: ^2.24
- pestphp/pest-plugin-laravel: ^2.2
This package is auto-updated.
Last update: 2025-06-20 04:02:01 UTC
README
A simple Laravel package that adds a macro to the HTTP client for automatic retrying of requests that fail due to connection timeouts.
Features
- Adds a
withTimeoutRetry()
macro to Laravel's HTTP client. - Retries requests on
ConnectionException
(timeout). - Configurable retry attempts, delay, and enable/disable via config or environment variables.
Installation
Require the package via Composer:
composer require 3dgoo/laravel-http-timeout-retry-provider
The service provider will be auto-discovered by Laravel.
Configuration
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_ATTEMPTS=3 HTTP_RETRY_DELAY=100 HTTP_RETRY_ENABLED=true
Usage
Use the withTimeoutRetry() macro on any HTTP client request:
Http::withTimeoutRetry()->get('https://example.com/api');
We can also pass optional parameters to override the default number of retry attempts, the default retry delay and a callback function to override the retry logic.
Http::withTimeoutRetry( 5, 250, function ($exception) { return $exception instanceof \RuntimeException; } )->get('https://example.com/api');
This will retry the request up to the configured number of times if a connection timeout occurs.
Default config (config/http.php):
```php
return [
'retry_attempts' => env('HTTP_RETRY_ATTEMPTS', 3),
'retry_delay' => env('HTTP_RETRY_DELAY', 100),
'retry_enabled' => env('HTTP_RETRY_ENABLED', true),
];
License
MIT