RetryPlugin
in package
implements
Plugin
FinalYes
Retry the request if an exception is thrown.
By default will retry only one time.
Tags
Table of Contents
Interfaces
- Plugin
- A plugin is a middleware to transform the request and/or the response.
Properties
- $errorResponseDecider : callable
- $errorResponseDelay : callable
- $exceptionDecider : callable
- $exceptionDelay : callable
- $retry : int
- Number of retry before sending an exception.
- $retryStorage : array<string|int, mixed>
- Store the retry counter for each request.
Methods
- __construct() : mixed
- defaultErrorResponseDelay() : int
- defaultExceptionDelay() : int
- handleRequest() : Promise
- Handle the request and return the response coming from the next callable.
- retry() : ResponseInterface
Properties
$errorResponseDecider
private
callable
$errorResponseDecider
$errorResponseDelay
private
callable
$errorResponseDelay
$exceptionDecider
private
callable
$exceptionDecider
$exceptionDelay
private
callable
$exceptionDelay
$retry
Number of retry before sending an exception.
private
int
$retry
$retryStorage
Store the retry counter for each request.
private
array<string|int, mixed>
$retryStorage
= []
Methods
__construct()
public
__construct([array{'retries'?: int, 'error_response_decider'?: callable, 'exception_decider'?: callable, 'error_response_delay'?: callable, 'exception_delay'?: callable} $config = [] ]) : mixed
Parameters
- $config : array{'retries'?: int, 'error_response_decider'?: callable, 'exception_decider'?: callable, 'error_response_delay'?: callable, 'exception_delay'?: callable} = []
-
Configuration options:
- retries: Number of retries to attempt if an exception occurs before letting the exception bubble up
- error_response_decider: A callback that gets a request and response to decide whether the request should be retried
- exception_decider: A callback that gets a request and an exception to decide after a failure whether the request should be retried
- error_response_delay: A callback that gets a request and response and the current number of retries and returns how many microseconds we should wait before trying again
- exception_delay: A callback that gets a request, an exception and the current number of retries and returns how many microseconds we should wait before trying again
defaultErrorResponseDelay()
public
static defaultErrorResponseDelay(RequestInterface $request, ResponseInterface $response, int $retries) : int
Parameters
- $request : RequestInterface
- $response : ResponseInterface
- $retries : int
-
The number of retries we made before. First time this get called it will be 0.
Return values
intdefaultExceptionDelay()
public
static defaultExceptionDelay(RequestInterface $request, ClientExceptionInterface $e, int $retries) : int
Parameters
- $request : RequestInterface
- $e : ClientExceptionInterface
- $retries : int
-
The number of retries we made before. First time this get called it will be 0.
Return values
inthandleRequest()
Handle the request and return the response coming from the next callable.
public
handleRequest(RequestInterface $request, callable $next, callable $first) : Promise
Parameters
- $request : RequestInterface
- $next : callable
-
Next middleware in the chain, the request is passed as the first argument
- $first : callable
-
First middleware in the chain, used to to restart a request
Return values
Promise —Resolves a PSR-7 Response or fails with an Http\Client\Exception (The same as HttpAsyncClient)
retry()
private
retry(RequestInterface $request, callable $next, callable $first, string $chainIdentifier, int $delay) : ResponseInterface
Parameters
- $request : RequestInterface
- $next : callable
- $first : callable
- $chainIdentifier : string
- $delay : int