File: backoff-plugin.rst

package info (click to toggle)
php-guzzle 3.9.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,084 kB
  • ctags: 7,622
  • sloc: php: 31,344; xml: 176; makefile: 144; python: 45; sh: 5
file content (22 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
====================
Backoff retry plugin
====================

The ``Guzzle\Plugin\Backoff\BackoffPlugin`` automatically retries failed HTTP requests using custom backoff strategies:

.. code-block:: php

    use Guzzle\Http\Client;
    use Guzzle\Plugin\Backoff\BackoffPlugin;

    $client = new Client('http://www.test.com/');
    // Use a static factory method to get a backoff plugin using the exponential backoff strategy
    $backoffPlugin = BackoffPlugin::getExponentialBackoff();

    // Add the backoff plugin to the client object
    $client->addSubscriber($backoffPlugin);

The BackoffPlugin's constructor accepts a ``Guzzle\Plugin\Backoff\BackoffStrategyInterface`` object that is used to
determine when a retry should be issued and how long to delay between retries. The above code example shows how to
attach a BackoffPlugin to a client that is pre-configured to retry failed 500 and 503 responses using truncated
exponential backoff (emulating the behavior of Guzzle 2's ExponentialBackoffPlugin).