for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the hogosha-monitor package
*
* Copyright (c) 2016 Guillaume Cavana
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* Feel free to edit as you please, and have fun.
* @author Guillaume Cavana <[email protected]>
*/
namespace Hogosha\Monitor\Middleware;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
/**
* Class Backoff.
class Backoff
{
* decider.
* @return callable
public static function decider()
return function (
$retries,
Request $request,
Response $response = null,
RequestException $exception = null
) {
// Limit to 5 retry max
if ($retries >= 3) {
return false;
}
// Retry connection exceptions
if ($exception instanceof ConnectException) {
return true;
if ($response) {
// Retry if we have a serve error
if ($response->getStatusCode() >= 500) {
};
* delay.
public static function delay()
return function ($numberOfRetries) {
return 1000 * $numberOfRetries;