PHPackages                             3dgoo/laravel-http-timeout-retry-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. 3dgoo/laravel-http-timeout-retry-provider

ActiveLibrary[HTTP &amp; Networking](/categories/http)

3dgoo/laravel-http-timeout-retry-provider
=========================================

Http timeout retry provider for Laravel

1.1.2(10mo ago)053[1 PRs](https://github.com/3Dgoo/laravel-http-timeout-retry/pulls)MITPHPPHP ^8.1 || ^8.2 || ^8.3 || ^8.4CI passing

Since Jun 20Pushed 5mo agoCompare

[ Source](https://github.com/3Dgoo/laravel-http-timeout-retry)[ Packagist](https://packagist.org/packages/3dgoo/laravel-http-timeout-retry-provider)[ RSS](/packages/3dgoo-laravel-http-timeout-retry-provider/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (8)Versions (9)Used By (0)

Http timeout retry provider for Laravel
=======================================

[](#http-timeout-retry-provider-for-laravel)

A Laravel package that adds retry functionality to Http requests with configurable timeout handling and HTTP method filtering.

Features
--------

[](#features)

- Adds a `withTimeoutRetry()` macro to Laravel's HTTP client
- Retries requests on `ConnectionException` (timeout) and other configurable exceptions
- **Http method filtering** - Configure which methods (GET, POST, etc.) are safe to retry
- Configurable retry attempts, delay, and enable/disable via config or environment variables
- Optional logging of retry attempts with configurable log levels and channels
- Runtime parameter overrides for fine-grained control

Installation
------------

[](#installation)

Require the package via Composer:

```
composer require 3dgoo/laravel-http-timeout-retry-provider
```

The service provider will be auto-discovered by Laravel.

Configuration
-------------

[](#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_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=
```

### Configuration Options

[](#configuration-options)

- **HTTP\_RETRY\_ENABLED**: Master switch to enable/disable retry functionality
- **HTTP\_RETRY\_ATTEMPTS**: Number of retry attempts (0-100)
- **HTTP\_RETRY\_DELAY**: Base delay between retries in milliseconds (minimum 10ms)
- **HTTP\_RETRY\_ALLOWED\_METHODS**: Comma-separated list of HTTP methods allowed for retry
- **HTTP\_RETRY\_LOGGING\_ENABLED**: Enable logging of retry attempts
- **HTTP\_RETRY\_LOGGING\_LEVEL**: Log level for retry messages
- **HTTP\_RETRY\_LOGGING\_CHANNEL**: Custom log channel (optional)

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

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);
```

### Advanced Usage with Parameters

[](#advanced-usage-with-parameters)

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);
```

### HTTP Method Filtering

[](#http-method-filtering)

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');
```

### Overriding Method Filtering

[](#overriding-method-filtering)

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');
```

Method Safety Guide
-------------------

[](#method-safety-guide)

Different HTTP methods have different safety characteristics:

### ✅ Safe Methods (Default retry enabled)

[](#-safe-methods-default-retry-enabled)

- **GET, HEAD, OPTIONS**: Idempotent and safe, no side effects
- These are the recommended defaults for retry

### ⚠️ Potentially Unsafe Methods (Require explicit opt-in)

[](#️-potentially-unsafe-methods-require-explicit-opt-in)

- **POST**: Not idempotent, may create duplicate resources
- **PUT**: Idempotent by spec, but implementation varies
- **PATCH**: Not idempotent, partial updates can cause issues
- **DELETE**: Idempotent but potentially destructive

### Configuration Examples

[](#configuration-examples)

```
// 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' => ['*'],
```

Logging
-------

[](#logging)

When logging is enabled, retry attempts are logged with detailed information including the HTTP method:

- **Log Level**: Configurable via `HTTP_RETRY_LOGGING_LEVEL` (default: `info`)
- **Log Channel**: Configurable via `HTTP_RETRY_LOGGING_CHANNEL` (uses default log channel if not set)
- **Log Message**: Includes HTTP method, attempt number, total attempts, URL, and exception details

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"
}

```

Configuration File
------------------

[](#configuration-file)

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),
        ],
    ],
];
```

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance63

Regular maintenance activity

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

7

Last Release

321d ago

PHP version history (2 changes)1.0.0PHP ^8.1

1.1.0PHP ^8.1 || ^8.2 || ^8.3 || ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/d291c7429ff8684f948ffb3180ae3d1e78aa53bb6c79bd9d7afb57752e441486?d=identicon)[3Dgoo](/maintainers/3Dgoo)

---

Top Contributors

[![3Dgoo](https://avatars.githubusercontent.com/u/2616373?v=4)](https://github.com/3Dgoo "3Dgoo (12 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

httplaraveltimeoutretry

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/3dgoo-laravel-http-timeout-retry-provider/health.svg)

```
[![Health](https://phpackages.com/badges/3dgoo-laravel-http-timeout-retry-provider/health.svg)](https://phpackages.com/packages/3dgoo-laravel-http-timeout-retry-provider)
```

###  Alternatives

[matthewbdaly/laravel-etag-middleware

A Laravel middleware for adding ETags to HTTP requests to improve response times

64326.0k2](/packages/matthewbdaly-laravel-etag-middleware)[huang-yi/shadowfax

Run Laravel on Swoole.

3511.7k](/packages/huang-yi-shadowfax)[tomschlick/request-migrations

HTTP Request Migrations

1844.5k](/packages/tomschlick-request-migrations)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)[laragear/json

Easily retrieve and manipulate `Json` across your application.

363.5k](/packages/laragear-json)[laragear/api-manager

Manage multiple REST servers to make requests in few lines and fluently.

161.8k](/packages/laragear-api-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
