Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class ExponentialBackoff.
Exponential backoff implementation.
Namespace
Google \ Cloud \ CoreMethods
__construct
Parameters | |
---|---|
Name | Description |
retries |
int
[optional] Number of retries for a failed request. |
retryFunction |
callable
[optional] returns bool for whether or not to retry |
retryListener |
callable
[optional] Runs after the $retryFunction. Unlike the $retryFunction,this function isn't responsible to decide if a retry should happen or not, but it gives the users flexibility to consume exception messages and add custom logic. Function definition should match: function (\Exception $e, int $attempt, array $arguments): array Ex: One might want to change headers on every retry, this function can be used to achieve such a functionality. |
execute
Executes the retry process.
Parameters | |
---|---|
Name | Description |
function |
callable
|
arguments |
array
[optional] |
Returns | |
---|---|
Type | Description |
mixed |
setDelayFunction
If not set, defaults to using usleep
.
Parameter | |
---|---|
Name | Description |
delayFunction |
callable
|
Returns | |
---|---|
Type | Description |
void |
setCalcDelayFunction
If not set, defaults to using ExponentialBackoff::calculateDelay().
Parameter | |
---|---|
Name | Description |
calcDelayFunction |
callable
|
Returns | |
---|---|
Type | Description |
void |
static::calculateDelay
Calculates exponential delay.
Parameter | |
---|---|
Name | Description |
attempt |
int
The attempt number used to calculate the delay. |
Returns | |
---|---|
Type | Description |
int |
Constants
MAX_DELAY_MICROSECONDS
Value: 60000000