backoff-plugin.rst 1014 B

12345678910111213141516171819202122
  1. ====================
  2. Backoff retry plugin
  3. ====================
  4. The ``Guzzle\Plugin\Backoff\BackoffPlugin`` automatically retries failed HTTP requests using custom backoff strategies:
  5. .. code-block:: php
  6. use Guzzle\Http\Client;
  7. use Guzzle\Plugin\Backoff\BackoffPlugin;
  8. $client = new Client('http://www.test.com/');
  9. // Use a static factory method to get a backoff plugin using the exponential backoff strategy
  10. $backoffPlugin = BackoffPlugin::getExponentialBackoff();
  11. // Add the backoff plugin to the client object
  12. $client->addSubscriber($backoffPlugin);
  13. The BackoffPlugin's constructor accepts a ``Guzzle\Plugin\Backoff\BackoffStrategyInterface`` object that is used to
  14. determine when a retry should be issued and how long to delay between retries. The above code example shows how to
  15. attach a BackoffPlugin to a client that is pre-configured to retry failed 500 and 503 responses using truncated
  16. exponential backoff (emulating the behavior of Guzzle 2's ExponentialBackoffPlugin).