2017 © Pedro Peláez
 

library guzzle

Retrying behavior for Guzzle

image

mikeevstropov/guzzle

Retrying behavior for Guzzle

  • Friday, July 7, 2017
  • by mikeevstropov
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

mikeevstropov/guzzle

Retrying behavior for Guzzle, (*1)

Installation

Add dependency mikeevstropov/guzzle, (*2)

$ composer require mikeevstropov/guzzle

New options

  • requests_limit, (*3)

    Accepts:, (*4)

    • integer - positive integer

    Default:, (*5)

    • 1 - only one attempt

    Maximum number of attempts to receive a response., (*6)

  • repeat_on, (*7)

    Accepts:, (*8)

    • array - array with a numeric index

    Default:, (*9)

    • array(0, 5) - repeat failed request or if response code is 5xx

    List of error codes for retrying requests:, (*10)

    • array(5) - on GuzzleHttp\Exception\ServerException (5xx code)
    • array(4) - on GuzzleHttp\Exception\ClientException (4xx code)
    • array(0) - other TransferException like GuzzleHttp\Exception\ConnectException

    You can combine it like array(4, 5)., (*11)

Usage

<?php

$client = new \GuzzleHttp\Client();

// Let's try to request "http://httpstat.us/503" that
// page will always return "503 Service Unavailable"
$response = $client->get('http://httpstat.us/503', [
    'requests_limit' => 3,
]); // will thrown GuzzleHttp\Exception\ServerException after 3 attempts

// We can pass option "repeat_on" to prevent retrying
// if response has code 5xx (by default [0, 5])
$response = $client->get('http://httpstat.us/503', [
    'requests_limit' => 3,
    'repeat_on' => array(0, 4)
]); // will thrown GuzzleHttp\Exception\ServerException after first request

// But same options with request to the page that return 4xx
// will have 3 attempts, because we pass "4" as array item in
// option "repeat_on"
$response = $client->get('http://httpstat.us/402', [
    'requests_limit' => 3,
    'repeat_on' => array(0, 4)
]); // will thrown GuzzleHttp\Exception\ServerException after 3 attempts

Development

Clone, (*12)

$ git clone https://github.com/mikeevstropov/guzzle.git

Go to project, (*13)

$ cd guzzle

Install dependencies, (*14)

$ composer install

Increase composer timeout. Since composer by default set it to 300 seconds., (*15)

$ composer config --global process-timeout 600

Run the tests, (*16)

$ composer test

The Versions

07/07 2017

dev-master

9999999-dev

Retrying behavior for Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Evstropov

07/07 2017

1.0.0

1.0.0.0

Retrying behavior for Guzzle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Evstropov