Download the PHP package shoxcie/batch-http-client without Composer
On this page you can find all versions of the php package shoxcie/batch-http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shoxcie/batch-http-client
More information about shoxcie/batch-http-client
Files in shoxcie/batch-http-client
Package batch-http-client
Short Description HTTP request batch executor with individual retries, built on Symfony HttpClient.
License MIT
Informations about the package batch-http-client
Batch HTTP Client
HTTP request batch executor with individual retries, built on Symfony HttpClient.
Fire multiple HTTP requests in parallel. Each request retries independently without blocking others.
Requirements
- PHP 8.4+
- Symfony HttpClient 8.0+
Installation
Usage
Retries
Any non-2xx response or transport error (connection timeout, DNS failure) triggers a retry. Transport exception retries can be disabled per request with retryOnTransportException: false.
Retry options
Override options on retry with a static array:
Or dynamically with a Closure:
Retry options are merged onto the original options via array_replace_recursive().
Callbacks
Error handling
By default, if a request exhausts all retries, the last exception is rethrown and all in-flight requests are cancelled:
Set throwOnExhausted: false for optional requests. Failed optional requests return null in the results array:
Response decoding
By default, responses are decoded as JSON (toArray()). Set decodeJson: false to get raw content (getContent()):
Response parsing / validation
parseResponse runs after the body is decoded and before onSuccess, only on a 2xx response. The return value replaces the entry in the results array, so it doubles as a custom parser:
Throw InvalidResponseException from the parser to reject a semantically invalid 2xx response and trigger a retry (counts against maxRetries, fires onRetry, and on exhaustion fires onExhausted plus rethrows if throwOnExhausted: true):
Any other Throwable from the parser is treated as an unexpected error and routes to onAbort, cancelling the whole batch.
Custom HTTP client
Pass any HttpClientInterface implementation:
RequestConfig reference
| Parameter | Type | Default | Description |
|---|---|---|---|
method |
string |
(required) | HTTP method |
url |
string |
(required) | Request URL |
options |
array |
[] |
Symfony HttpClient options |
retryOptions |
array\|Closure |
[] |
Options merged on retry, or Closure receiving (string $key, int $retries, ExceptionInterface\|InvalidResponseException $e) |
throwOnExhausted |
bool |
true |
Rethrow exception after retries exhausted |
decodeJson |
bool |
true |
Decode response as JSON |
maxRetries |
int |
0 |
Maximum retry attempts |
retryOnTransportException |
bool |
true |
Retry on transport errors (timeouts, DNS) |
parseResponse |
Closure\|null |
null |
Runs on 2xx responses before onSuccess. Receives (string $key, int $retries, mixed $result, ResponseInterface $response); return value replaces the result. Throw InvalidResponseException to retry. |
[!IMPORTANT] The
user_dataoption is reserved for internal key correlation — passing it inoptionsorretryOptionsthrowsInvalidArgumentException.
Upgrading
See the upgrade/ folder for migration guides between major versions.
License
MIT — see LICENSE for details.