You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Client::withRetryPolicy()/setRetryPolicy()/getRetryPolicy() enable automatic
retry of transient failures (connection errors, timeouts, 408/425/429/5xx) with
exponential backoff, bounded jitter, a max-attempts cap and Retry-After support.
New InitPHP\HTTP\Client\Retry\ namespace; the single cURL attempt is exposed
as a protected Client::transport() seam. Backward compatible: with no policy the
client stays single-attempt and still returns (never throws) 4xx/5xx per PSR-18.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
14
-**Content-Type-aware body parsing** in `createFromGlobals` (JSON / urlencoded / multipart).
15
15
-**nginx + php-fpm header fallback** in `createFromGlobals` for environments without `apache_request_headers()`.
16
16
-**`Client::withTimeout()` / `withConnectTimeout()` / `withFollowRedirects()` / `withCurlOptions()`** for production-grade configuration.
17
+
-**Opt-in HTTP client resilience layer** — `Client::withRetryPolicy()` / `setRetryPolicy()` / `getRetryPolicy()` enable automatic retry of transient failures (connection errors, timeouts, and the retryable status set `408/425/429/500/502/503/504`) with exponential backoff, bounded jitter, a max-attempts cap, and `Retry-After` support. New `InitPHP\HTTP\Client\Retry\` namespace: `RetryPolicy` (config value object), `Backoff` (exponential + equal-jitter calculator), `RetryAfter` (RFC 7231 header parser), `Sleeper`/`SleeperInterface` (injectable pacing). The single cURL attempt is exposed as a protected `Client::transport()` seam for testing/overriding. **Backward compatible: with no policy attached the client stays single-attempt** and still returns (never throws) 4xx/5xx per PSR-18.
17
18
-**`Facadable` trait and `FacadableInterface`** — canonical names replacing the misspelled `Facadeble[Interface]` (old names kept as `@deprecated` aliases).
18
19
-**`docs/` directory** with PSR-7/17/18 guides, emitter walk-throughs, recipes, status-code reference and an upgrade guide.
19
20
-**Comprehensive `tests/Unit/` suite** complementing the upstream PSR integration tests.
PSR-18 contract is honoured: **4xx/5xx responses are returned, not thrown**. Only transport failures raise `Psr\Http\Client\NetworkExceptionInterface`.
148
148
149
+
#### Resilience: retry with exponential backoff + jitter
150
+
151
+
The client is single-attempt by default. Attach a `RetryPolicy` to opt in to
152
+
automatic retries of *transient* failures — connection errors, timeouts and the
153
+
retryable HTTP status set (`408, 425, 429, 500, 502, 503, 504` by default) — with
154
+
exponential backoff, bounded jitter, a hard max-attempts cap, and `Retry-After`
155
+
support:
156
+
157
+
```php
158
+
use InitPHP\HTTP\Client\Client;
159
+
use InitPHP\HTTP\Client\Retry\RetryPolicy;
160
+
161
+
$client = (new Client())->withRetryPolicy(new RetryPolicy(
162
+
maxAttempts: 4, // 1 initial try + up to 3 retries
163
+
baseDelay: 0.1, // first backoff interval, seconds
164
+
multiplier: 2.0, // 0.1s, 0.2s, 0.4s, ...
165
+
maxDelay: 30.0, // cap on any single interval
166
+
jitter: 0.5, // up to 50% random reduction (anti thundering-herd)
167
+
));
168
+
169
+
// Every verb helper inherits the policy transparently.
0 commit comments