Advanced Retry Implementation

v0.2.2 2015-09-29 16:20 UTC

This package is auto-updated.

Last update: 2024-05-18 05:40:19 UTC


Advanced retry implementation.


composer require gos/yolo


Perform an action

$pusher->push($notification); #send notification over network

With YOLO :

use Gos\Component\Yolo\Yolo;

$maxRetry = 10; // Default is 5
$timeout = 10; // Default is 5 (in second), set 0 for not timeout
$allowedException = ['RuntimeException']; // empty by default, consider exception as a "success"
$yoloPush = new Yolo(array($pusher, 'push'), array($notification), $maxRetry, $timeout);

Sometimes we need more swag to retry over a webservice.

use Gos\Component\Yolo\Yolo;

$yoloPush = new Yolo(array($pusher, 'push'), array($notification));
    $result = false;
    if ($fp = @fsockopen('my-web-service.dev', 1337, $errCode, $errStr, 1)) {
        $result = true;

    return $result;

If your operation have an hight cost, perform it when service is available instead of dummy retry.

You also can do :

use Gos\Component\Yolo\Yolo;

$yoloPush = new Yolo(array($pusher, 'push'), array($notification));

By implementing Gos\Component\Yolo\YoloInterface on your object. Add isAvailable and return true when it's ok.

You also can attach a logger to yolo (We implement Psr\Log\LoggerAwareInterface) . Swag

use Gos\Component\Yolo\Yolo;

$yolo = new Yolo(function(){});

Built in Callback

Ping Back

use Gos\Component\Yolo\Yolo;
use Gos\Component\Yolo\Callback\PingBack;

$pingger = new PingBack('', 80);

$yoloPush = new Yolo(function(){});