Download the PHP package guzzlehttp/retry-subscriber without Composer

On this page you can find all versions of the php package guzzlehttp/retry-subscriber. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package retry-subscriber


Guzzle Retry Subscriber

Retries failed HTTP requests using customizable retry strategies.

Here's a simple example of how it's used:

use GuzzleHttp\Subscriber\Retry\RetrySubscriber;

// Retry 500 and 503 responses
$retry = new RetrySubscriber([
    'filter' => RetrySubscriber::createStatusFilter()
]);

$client = new GuzzleHttp\Client();
$client->getEmitter()->attach($retry);

Installing

Add the following to your composer.json:

{
    "require": {
        "guzzlehttp/retry-subscriber": "~2.0"
    }
}

Creating a RetrySubscriber

The constructor of the RetrySubscriber accepts an associative array of configuration options:

filter (callable) (Required) Filter used to determine whether or not to retry a request. The filter must be a callable that accepts the current number of retries as the first argument and a GuzzleHttp\Event\AbstractTransferEvent object as the second argument. The filter must return true or false to denote if the request must be retried. delay Callable that accepts the number of retries as the first argument and a GuzzleHttp\Event\AbstractTransferEvent as the second argument. The callable must return the amount of of time (in milliseconds) to delay.

If no delay configuration value is provided, then a default exponential backoff implementation is used.

max Integer representing the maximum number of retries to allow before giving up.

If no max configuration value is provided, then a request will be retried 5 times.

Determining what should be retried

The required filter option of the RetrySubscriber's constructor is a callable that is invoked to determine if a request should be retried.

When the filter is invoked, it is provided the current retry count for the request and a GuzzleHttp\Event\CompleteEvent or GuzzleHttp\Event\ErrorEvent (both events extend from GuzzleHttp\Event\AbstractTransferEvent, so you should typehint on that). The filter must then return true if the request should be retried, or false if it should not be retried.

Here's an example of retrying failed 500 responses sent to the /foo endpoint:

use GuzzleHttp\Event\AbstractTransferEvent;
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;

$retry = new RetrySubscriber([
    'filter' => function ($retries, AbstractTransferEvent $event) {
        $resource = $event->getRequest()->getResource();
        // A response is not always received (e.g., for timeouts)
        $code = $event->getResponse()
            ? $event->getResponse()->getStatusCode()
            : null;

        return $resource == '/foo' && $code == 500;
    }
]);

$client = new GuzzleHttp\Client();
$client->getEmitter()->attach($retry);

Filter Chains

You can create more customizable retry logic with filter chains, which are created using the static RetrySubscriber::createChainFilter() method. This method accepts an array of callable filters that are each invoked one after the other. The filters in the chain should return one of the following values, which affects how the rest of the chain is executed.

Here's an example using filter chains that retries failed 500 and 503 responses for only idempotent or "safe" requests as defined by RFC 7231.

use GuzzleHttp\Event\AbstractTransferEvent;
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;

// Retry 500 and 503 responses that were sent as GET and HEAD requests.
$filter = RetrySubscriber::createChainFilter([
    // Does early filter to force non-idempotent methods to NOT be retried.
    RetrySubscriber::createIdempotentFilter(),
    // Performs the last check, returning ``true`` or ``false`` based on
    // if the response received a 500 or 503 status code.
    RetrySubscriber::createStatusFilter([500, 503])
]);

$retry = new RetrySubscriber(['filter' => $filter]);
$client = new GuzzleHttp\Client();
$client->getEmitter()->attach($retry);

Customizing the amount of delay

delay is an optional configuration option in the RetrySubscriber's constructor that is a callable used to determine the amount of time to delay before retrying a request that has been marked as needing a retry. The callable accepts the current number of retries and either a GuzzleHttp\Event\CompleteEvent or a GuzzleHttp\Event\ErrorEvent. The function must then return an integer or float representing the amount of time in milliseconds to sleep.

Omitting this argument will use a default exponential backoff strategy.

Here's an example of creating a custom delay that always delays for 1 millisecond:

use GuzzleHttp\Subscriber\Retry\RetrySubscriber;

$retry = new RetrySubscriber([
    'filter' => RetrySubscriber::createStatusFilter(),
    'delay'  => function ($number, $event) { return 1; }
]);

Changing the max number of retries

You can also specify an optional max number of retries in the max configuration option of the RetrySubscriber's constructor. If not specified, a request can be retried up to 5 times before it is allowed to fail.

use GuzzleHttp\Subscriber\Retry\RetrySubscriber;

$retry = new RetrySubscriber([
    'filter' => RetrySubscriber::createStatusFilter(),
    'max'    => 3
]);

All versions of retry-subscriber with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
guzzlehttp/guzzle Version ~5.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package guzzlehttp/retry-subscriber contains the following files

Loading the files please wait ....