Download the PHP package philiprehberger/http-retry-client without Composer

On this page you can find all versions of the php package philiprehberger/http-retry-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http-retry-client

PHP HTTP Retry Client

Tests Latest Version on Packagist Last updated

HTTP client wrapper with automatic retries, exponential backoff, jitter, circuit breaker, and request logging.

Requirements

Installation

Usage

Basic Usage

Implement the HttpExecutor interface to wrap your preferred HTTP client:

Custom Retry Policy

Fluent Builder

Handling Retry Results

Jitter Modes

Control the jitter algorithm used for backoff delays:

Retry Hooks

Register callbacks that run before and after each retry attempt:

Custom Retryable Status Codes

Circuit Breaker

Protect downstream services with a circuit breaker that opens after consecutive failures:

The circuit breaker transitions through three states:

Request Logging

Log HTTP requests, responses, and failures for observability:

Timeout Configuration

Set connection and request timeouts:

API

RetryPolicy

Parameter Type Default Description
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<int> [429, 500, 502, 503, 504] Status codes that trigger a retry
jitterMode JitterMode JitterMode::Full Jitter algorithm (Full, Equal, Decorrelated)
beforeRetry ?callable null Callback invoked before each retry (int $attempt, ?\Throwable $error)
afterRetry ?callable null Callback invoked after each retry (int $attempt, ?\Throwable $error)
connectionTimeoutMs ?int null Default connection timeout in milliseconds
requestTimeoutMs ?int null Default request timeout in milliseconds

RetryPolicyBuilder

Method Description
maxRetries(int $maxRetries) Set max retry attempts
baseDelay(int $ms) Set base delay in milliseconds
maxDelay(int $ms) Set max delay cap in milliseconds
multiplier(float $multiplier) Set backoff multiplier
withJitter(bool $jitter) Enable/disable jitter
withoutJitter() Disable jitter
retryOn(array $codes) Set retryable status codes
jitterMode(JitterMode $mode) Set jitter algorithm
beforeRetry(callable $callback) Register before-retry callback
afterRetry(callable $callback) Register after-retry callback
connectionTimeout(int $ms) Set connection timeout in milliseconds
requestTimeout(int $ms) Set request timeout in milliseconds
withCircuitBreaker(int $failureThreshold, int $recoveryTimeout) Enable circuit breaker
withLogger(callable $logger, bool $logBodies) Enable request/response logging
build() Build the RetryPolicy

RetryClient

Method Description
send(HttpRequest $request): RetryResult Send a request with automatic retries

RetryResult

Property Type Description
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)

Method Description
execute(HttpRequest $request): HttpResponse Execute an HTTP request

CircuitBreakerWrapper

Method Description
__construct(int $failureThreshold, int $recoveryTimeoutSeconds) Create a circuit breaker
execute(callable $action): mixed Execute action through the circuit breaker
isOpen(): bool Check if circuit is open
isClosed(): bool Check if circuit is closed
state(): string Get current state (closed, open, half_open)
reset(): void Reset to closed state
failureCount(): int Get current failure count

RequestLogger

Method Description
__construct(callable $logger, bool $logBodies) Create a logger
logRequest(HttpRequest $request, int $attempt): void Log an outgoing request
logResponse(HttpResponse $response, int $attempt, float $durationMs): void Log a response
logFailure(\Throwable $exception, int $attempt): void Log a failure

MaxRetriesExceededException

Property Type Description
attempts int Total number of attempts made

CircuitBreakerOpenException

Thrown when a request is rejected because the circuit breaker is in the open state.

Development

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT


All versions of http-retry-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package philiprehberger/http-retry-client contains the following files

Loading the files please wait ...