BackoffPlugin
extends AbstractHasDispatcher
in package
implements
EventSubscriberInterface
Plugin to automatically retry failed HTTP requests using a backoff strategy
Table of Contents
Interfaces
- EventSubscriberInterface
- An EventSubscriber knows himself what events he is interested in.
Constants
- DELAY_PARAM = \Guzzle\Http\Curl\CurlMultiInterface::BLOCKING
- RETRY_EVENT = 'plugins.backoff.retry'
- RETRY_PARAM = 'plugins.backoff.retry_count'
Properties
Methods
- __construct() : mixed
- addSubscriber() : self
- Add an event subscriber to the dispatcher
- dispatch() : Event
- Helper to dispatch Guzzle events and set the event name on the event
- getAllEvents() : array<string|int, mixed>
- Get a list of all of the events emitted from the class
- getEventDispatcher() : EventDispatcherInterface
- Get the EventDispatcher of the request
- getExponentialBackoff() : self
- Retrieve a basic truncated exponential backoff plugin that will retry HTTP errors and cURL errors
- getSubscribedEvents() : array<string|int, mixed>
- Returns an array of event names this subscriber wants to listen to.
- onRequestPoll() : mixed
- Called when a request is polling in the curl multi object
- onRequestSent() : mixed
- Called when a request has been sent and isn't finished processing
- setEventDispatcher() : self
- Set the EventDispatcher of the request
Constants
DELAY_PARAM
public
mixed
DELAY_PARAM
= \Guzzle\Http\Curl\CurlMultiInterface::BLOCKING
RETRY_EVENT
public
mixed
RETRY_EVENT
= 'plugins.backoff.retry'
RETRY_PARAM
public
mixed
RETRY_PARAM
= 'plugins.backoff.retry_count'
Properties
$eventDispatcher
protected
EventDispatcherInterface
$eventDispatcher
$strategy
protected
BackoffStrategyInterface
$strategy
Backoff strategy
Methods
__construct()
public
__construct([BackoffStrategyInterface $strategy = null ]) : mixed
Parameters
- $strategy : BackoffStrategyInterface = null
-
The backoff strategy used to determine whether or not to retry and the amount of delay between retries.
addSubscriber()
Add an event subscriber to the dispatcher
public
addSubscriber(EventSubscriberInterface $subscriber) : self
Parameters
- $subscriber : EventSubscriberInterface
-
Event subscriber
Return values
selfdispatch()
Helper to dispatch Guzzle events and set the event name on the event
public
dispatch(mixed $eventName[, array<string|int, mixed> $context = array() ]) : Event
Parameters
- $eventName : mixed
-
Name of the event to dispatch
- $context : array<string|int, mixed> = array()
-
Context of the event
Return values
Event —Returns the created event object
getAllEvents()
Get a list of all of the events emitted from the class
public
static getAllEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>getEventDispatcher()
Get the EventDispatcher of the request
public
getEventDispatcher() : EventDispatcherInterface
Return values
EventDispatcherInterfacegetExponentialBackoff()
Retrieve a basic truncated exponential backoff plugin that will retry HTTP errors and cURL errors
public
static getExponentialBackoff([int $maxRetries = 3 ][, array<string|int, mixed> $httpCodes = null ][, array<string|int, mixed> $curlCodes = null ]) : self
Parameters
- $maxRetries : int = 3
-
Maximum number of retries
- $httpCodes : array<string|int, mixed> = null
-
HTTP response codes to retry
- $curlCodes : array<string|int, mixed> = null
-
cURL error codes to retry
Return values
selfgetSubscribedEvents()
Returns an array of event names this subscriber wants to listen to.
public
static getSubscribedEvents() : array<string|int, mixed>
The array keys are event names and the value can be:
- The method name to call (priority defaults to 0)
- An array composed of the method name to call and the priority
- An array of arrays composed of the method names to call and respective priorities, or 0 if unset
For instance:
- array('eventName' => 'methodName')
- array('eventName' => array('methodName', $priority))
- array('eventName' => array(array('methodName1', $priority), array('methodName2')))
Return values
array<string|int, mixed> —The event names to listen to
onRequestPoll()
Called when a request is polling in the curl multi object
public
onRequestPoll(Event $event) : mixed
Parameters
- $event : Event
onRequestSent()
Called when a request has been sent and isn't finished processing
public
onRequestSent(Event $event) : mixed
Parameters
- $event : Event
setEventDispatcher()
Set the EventDispatcher of the request
public
setEventDispatcher(EventDispatcherInterface $eventDispatcher) : self
Parameters
- $eventDispatcher : EventDispatcherInterface