RetryableHttpClient
in package
implements
HttpClientInterface, ResetInterface
uses
AsyncDecoratorTrait
Automatically retries failing HTTP requests.
Tags
Table of Contents
Interfaces
- HttpClientInterface
- Provides flexible methods for requesting HTTP resources synchronously or asynchronously.
- ResetInterface
- Provides a way to reset an object to its initial state.
Properties
- $baseUris : array<string|int, mixed>
- $logger : LoggerInterface|null
- $maxRetries : int
- $strategy : RetryStrategyInterface
Methods
- __construct() : mixed
- request() : ResponseInterface
- Requests an HTTP resource.
- stream() : ResponseStreamInterface
- withOptions() : static
- Returns a new instance of the client with new default options.
- getDelayFromHeader() : int|null
- passthru() : Generator
- shiftBaseUri() : array<string|int, mixed>
Properties
$baseUris
private
array<string|int, mixed>
$baseUris
= []
$logger
private
LoggerInterface|null
$logger
= null
$maxRetries
private
int
$maxRetries
= 3
$strategy
private
RetryStrategyInterface
$strategy
Methods
__construct()
public
__construct(HttpClientInterface $client[, RetryStrategyInterface|null $strategy = null ][, int $maxRetries = 3 ][, LoggerInterface|null $logger = null ]) : mixed
Parameters
- $client : HttpClientInterface
- $strategy : RetryStrategyInterface|null = null
- $maxRetries : int = 3
-
The maximum number of times to retry
- $logger : LoggerInterface|null = null
request()
Requests an HTTP resource.
public
request(string $method, string $url[, array<string|int, mixed> $options = [] ]) : ResponseInterface
Responses MUST be lazy, but their status code MUST be checked even if none of their public methods are called.
Implementations are not required to support all options described above; they can also support more custom options; but in any case, they MUST throw a TransportExceptionInterface when an unsupported option is passed.
Parameters
- $method : string
- $url : string
- $options : array<string|int, mixed> = []
Return values
ResponseInterfacestream()
public
stream(ResponseInterface|iterable<string|int, mixed> $responses[, float|null $timeout = null ]) : ResponseStreamInterface
Parameters
- $responses : ResponseInterface|iterable<string|int, mixed>
- $timeout : float|null = null
Return values
ResponseStreamInterfacewithOptions()
Returns a new instance of the client with new default options.
public
withOptions(array<string|int, mixed> $options) : static
Parameters
- $options : array<string|int, mixed>
Return values
staticgetDelayFromHeader()
private
getDelayFromHeader(array<string|int, mixed> $headers) : int|null
Parameters
- $headers : array<string|int, mixed>
Return values
int|nullpassthru()
private
passthru(AsyncContext $context, ChunkInterface|null $firstChunk, string &$content, ChunkInterface $lastChunk) : Generator
Parameters
- $context : AsyncContext
- $firstChunk : ChunkInterface|null
- $content : string
- $lastChunk : ChunkInterface
Return values
GeneratorshiftBaseUri()
private
static shiftBaseUri(array<string|int, mixed> $options, array<string|int, mixed> &$baseUris) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed>
- $baseUris : array<string|int, mixed>