GenericRetryStrategy
in package
implements
RetryStrategyInterface
Decides to retry the request when HTTP status codes belong to the given list of codes.
Tags
Table of Contents
Interfaces
Constants
- DEFAULT_RETRY_STATUS_CODES = [ 0 => self::IDEMPOTENT_METHODS, // for transport exceptions 423, 425, 429, 500 => self::IDEMPOTENT_METHODS, 502, 503, 504 => self::IDEMPOTENT_METHODS, 507 => self::IDEMPOTENT_METHODS, 510 => self::IDEMPOTENT_METHODS, ]
- IDEMPOTENT_METHODS = ['GET', 'HEAD', 'PUT', 'DELETE', 'OPTIONS', 'TRACE']
Properties
- $delayMs : mixed
- $jitter : mixed
- $maxDelayMs : mixed
- $multiplier : mixed
- $statusCodes : mixed
Methods
- __construct() : mixed
- getDelay() : int
- Returns the time to wait in milliseconds.
- shouldRetry() : bool|null
- Returns whether the request should be retried.
Constants
DEFAULT_RETRY_STATUS_CODES
public
mixed
DEFAULT_RETRY_STATUS_CODES
= [
0 => self::IDEMPOTENT_METHODS,
// for transport exceptions
423,
425,
429,
500 => self::IDEMPOTENT_METHODS,
502,
503,
504 => self::IDEMPOTENT_METHODS,
507 => self::IDEMPOTENT_METHODS,
510 => self::IDEMPOTENT_METHODS,
]
IDEMPOTENT_METHODS
public
mixed
IDEMPOTENT_METHODS
= ['GET', 'HEAD', 'PUT', 'DELETE', 'OPTIONS', 'TRACE']
Properties
$delayMs
private
mixed
$delayMs
$jitter
private
mixed
$jitter
$maxDelayMs
private
mixed
$maxDelayMs
$multiplier
private
mixed
$multiplier
$statusCodes
private
mixed
$statusCodes
Methods
__construct()
public
__construct([array<string|int, mixed> $statusCodes = self::DEFAULT_RETRY_STATUS_CODES ][, int $delayMs = 1000 ][, float $multiplier = 2.0 ][, int $maxDelayMs = 0 ][, float $jitter = 0.1 ]) : mixed
Parameters
- $statusCodes : array<string|int, mixed> = self::DEFAULT_RETRY_STATUS_CODES
-
List of HTTP status codes that trigger a retry
- $delayMs : int = 1000
-
Amount of time to delay (or the initial value when multiplier is used)
- $multiplier : float = 2.0
-
Multiplier to apply to the delay each time a retry occurs
- $maxDelayMs : int = 0
-
Maximum delay to allow (0 means no maximum)
- $jitter : float = 0.1
-
Probability of randomness int delay (0 = none, 1 = 100% random)
getDelay()
Returns the time to wait in milliseconds.
public
getDelay(AsyncContext $context, string|null $responseContent, TransportExceptionInterface|null $exception) : int
Parameters
- $context : AsyncContext
- $responseContent : string|null
- $exception : TransportExceptionInterface|null
Return values
intshouldRetry()
Returns whether the request should be retried.
public
shouldRetry(AsyncContext $context, string|null $responseContent, TransportExceptionInterface|null $exception) : bool|null
Parameters
- $context : AsyncContext
- $responseContent : string|null
-
Null is passed when the body did not arrive yet
- $exception : TransportExceptionInterface|null
Return values
bool|null —Returns null to signal that the body is required to take a decision