PHPackages                             philiprehberger/http-retry-client - 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. philiprehberger/http-retry-client

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

philiprehberger/http-retry-client
=================================

HTTP client wrapper with automatic retries, exponential backoff, and jitter

v1.0.2(4d ago)11MITPHPPHP ^8.2CI passing

Since Mar 13Pushed yesterdayCompare

[ Source](https://github.com/philiprehberger/http-retry-client)[ Packagist](https://packagist.org/packages/philiprehberger/http-retry-client)[ Docs](https://github.com/philiprehberger/http-retry-client)[ RSS](/packages/philiprehberger-http-retry-client/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (3)Used By (0)

PHP HTTP Retry Client
=====================

[](#php-http-retry-client)

[![Tests](https://github.com/philiprehberger/http-retry-client/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/http-retry-client/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/51f62d463ad23ce7f52f927874b5499b8d2a39818bee08b5a9ec68a4cb08dae8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f687474702d72657472792d636c69656e742e737667)](https://packagist.org/packages/philiprehberger/http-retry-client)[![License](https://camo.githubusercontent.com/4dc7785d6e574a294a79ff738278fa12ea2f7fcb981a3386c902b282e9033a51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f687474702d72657472792d636c69656e74)](LICENSE)

HTTP client wrapper with automatic retries, exponential backoff, and jitter.

Requirements
------------

[](#requirements)

- PHP 8.2+

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

[](#installation)

```
composer require philiprehberger/http-retry-client
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Implement the `HttpExecutor` interface to wrap your preferred HTTP client:

```
use PhilipRehberger\HttpRetry\Contracts\HttpExecutor;
use PhilipRehberger\HttpRetry\HttpRequest;
use PhilipRehberger\HttpRetry\HttpResponse;
use PhilipRehberger\HttpRetry\RetryClient;

class CurlExecutor implements HttpExecutor
{
    public function execute(HttpRequest $request): HttpResponse
    {
        $ch = curl_init($request->url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->method);

        if ($request->body !== null) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $request->body);
        }

        $body = curl_exec($ch);
        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        return new HttpResponse($statusCode, $body);
    }
}

$client = new RetryClient(new CurlExecutor());
$result = $client->send(new HttpRequest('GET', 'https://api.example.com/data'));

if ($result->successful()) {
    echo $result->body;
}
```

### Custom Retry Policy

[](#custom-retry-policy)

```
use PhilipRehberger\HttpRetry\RetryClient;
use PhilipRehberger\HttpRetry\RetryPolicy;

$policy = new RetryPolicy(
    maxRetries: 5,
    baseDelayMs: 200,
    maxDelayMs: 30000,
    multiplier: 2.0,
    jitter: true,
    retryableStatusCodes: [429, 500, 502, 503, 504],
);

$client = new RetryClient($executor, $policy);
```

### Fluent Builder

[](#fluent-builder)

```
use PhilipRehberger\HttpRetry\RetryPolicy;

$policy = RetryPolicy::builder()
    ->maxRetries(5)
    ->baseDelay(200)
    ->maxDelay(30000)
    ->multiplier(3.0)
    ->withoutJitter()
    ->retryOn([500, 502, 503])
    ->build();
```

### Handling Retry Results

[](#handling-retry-results)

```
use PhilipRehberger\HttpRetry\Exceptions\MaxRetriesExceededException;

try {
    $result = $client->send($request);

    echo "Status: {$result->statusCode}\n";
    echo "Attempts: {$result->attempts}\n";
    echo "Total delay: {$result->totalDelayMs}ms\n";
    echo "Was retried: " . ($result->wasRetried ? 'yes' : 'no') . "\n";
} catch (MaxRetriesExceededException $e) {
    echo "Failed after {$e->attempts} attempts: {$e->getMessage()}\n";
}
```

### Custom Retryable Status Codes

[](#custom-retryable-status-codes)

```
$policy = RetryPolicy::builder()
    ->retryOn([408, 429, 500, 502, 503, 504])
    ->build();
```

API
---

[](#api)

### `RetryPolicy`

[](#retrypolicy)

ParameterTypeDefaultDescription`maxRetries``int``3`Maximum number of retry attempts`baseDelayMs``int``100`Base delay in milliseconds`maxDelayMs``int``10000`Maximum delay cap in milliseconds`multiplier``float``2.0`Backoff multiplier`jitter``bool``true`Whether to add random jitter`retryableStatusCodes``array``[429, 500, 502, 503, 504]`Status codes that trigger a retry### `RetryClient`

[](#retryclient)

MethodDescription`send(HttpRequest $request): RetryResult`Send a request with automatic retries### `RetryResult`

[](#retryresult)

PropertyTypeDescription`statusCode``int`HTTP status code of the final response`body``string`Response body`headers``array`Response headers`attempts``int`Total number of attempts made`totalDelayMs``int`Total delay spent waiting (ms)`wasRetried``bool`Whether the request was retried`successful()``bool`Whether the status code is 2xx### `HttpExecutor` (Interface)

[](#httpexecutor-interface)

MethodDescription`execute(HttpRequest $request): HttpResponse`Execute an HTTP request### `MaxRetriesExceededException`

[](#maxretriesexceededexception)

PropertyTypeDescription`attempts``int`Total number of attempts madeDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance100

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Total

2

Last Release

4d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (9 commits)")

---

Tags

httppsr-18retryJitterbackoff

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-http-retry-client/health.svg)

```
[![Health](https://phpackages.com/badges/philiprehberger-http-retry-client/health.svg)](https://phpackages.com/packages/philiprehberger-http-retry-client)
```

###  Alternatives

[psr/http-client

Common interface for HTTP clients

1.7k665.1M1.7k](/packages/psr-http-client)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48246.1M329](/packages/php-http-curl-client)[elastic/transport

HTTP transport PHP library for Elastic products

1819.6M7](/packages/elastic-transport)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28132.9k](/packages/phpro-http-tools)[vultr/vultr-php

The Official Vultr API PHP Wrapper.

2342.1k1](/packages/vultr-vultr-php)[amphp/http-client-psr7

PSR-7 adapter for Amp's HTTP client.

1448.3k3](/packages/amphp-http-client-psr7)

PHPackages © 2026

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