cline/retry

Comprehensive retry strategies with exponential backoff, jitter, and circuit breaker support for PHP 8.4+

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/cline/retry

1.0.0 2025-10-31 13:43 UTC

This package is auto-updated.

Last update: 2025-10-31 13:47:28 UTC


README

GitHub Workflow Status Latest Version on Packagist Software License Total Downloads

A comprehensive retry library for PHP 8.4+ featuring multiple backoff strategies, jitter support, and a fluent interface for building resilient applications. Designed for handling transient failures in network requests, database operations, and external service calls.

Requirements

Requires PHP 8.4+

Installation

composer require cline/retry

Quick Start

use Cline\Retry\Retry;
use Cline\Retry\Strategy\ExponentialBackoff;
use function Cline\Retry\retry;

// Functional style with exponential backoff
$result = retry(5, ExponentialBackoff::milliseconds(100))(
    fn() => $apiClient->fetchData()
);

// OOP style with fluent interface
$result = Retry::times(5)
    ->withBackoff(ExponentialBackoff::seconds(1))
    ->withMaxDelay(30_000_000) // 30 seconds
    ->execute(fn() => $database->query());

Documentation

  • Backoff Strategies - All available backoff algorithms and when to use them
  • Retry Patterns - Common retry patterns for APIs, databases, and more
  • Functional API - Using the retry() function with closures
  • OOP API - Fluent interface with conditional retries and max delays
  • Examples - Real-world usage examples and patterns

Features

  • 8 Backoff Strategies: Constant, Linear, Exponential, Exponential+Jitter, Fibonacci, Decorrelated Jitter, Polynomial, and Max Delay Decorator
  • Functional & OOP APIs: Choose the style that fits your codebase
  • Conditional Retries: Retry only on specific exceptions or conditions
  • Max Delay Caps: Prevent exponential backoff from growing too large
  • Immutable: All configuration methods return new instances
  • Type Safe: Full PHP 8.4 type coverage with readonly properties
  • Well Tested: 244 tests with 2,539 assertions covering all edge cases

Change log

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please use the GitHub security reporting form rather than the issue queue.

Credits

License

The MIT License. Please see License File for more information.