Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

mikeevstropov/guzzle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mikeevstropov/guzzle

Retrying behavior for Guzzle

Installation

Add dependency mikeevstropov/guzzle

$ composer require mikeevstropov/guzzle

New options

  • requests_limit

    Accepts:

    • integer - positive integer

    Default:

    • 1 - only one attempt

    Maximum number of attempts to receive a response.

  • repeat_on

    Accepts:

    • array - array with a numeric index

    Default:

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

    List of error codes for retrying requests:

    • 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).

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

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

Go to project

$ cd guzzle

Install dependencies

$ composer install

Increase composer timeout. Since composer by default set it to 300 seconds.

$ composer config --global process-timeout 600

Run the tests

$ composer test

About

Retrying behavior for Guzzle

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages