PHP code example of diephp / perhaps

1. Go to this page and download the library: Download diephp/perhaps library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

diephp / perhaps example snippets


    'providers' => [
        // ...
        \DiePHP\Perhaps\Providers\PerhapsServiceProvider::class,
    ],
    

     return [
         App\Providers\AppServiceProvider::class,
         ...
         \DiePHP\Perhaps\Providers\PerhapsServiceProvider::class,
     ];
     

use DiePHP\Perhaps\Facades\Perhaps;

Perhaps::retry(function() {
    // Your logic here
}, 3); // Retry 3 times

use DiePHP\Perhaps\Facades\Perhaps;
use DiePHP\Sequences\LogarithmicSequence;

Perhaps::retry(function() {
    // Your logic here
}, 10, new LogarithmicSequence(1000000, 100)); // Retry 10 times with logarithmicSequence delay

use DiePHP\Perhaps\Facades\Perhaps;
use DiePHP\Sequences\ProgressiveSequence;

Perhaps::retry(function() {
    // Your logic here
}, 20, new ProgressiveSequence(1000000, 100)); // Retry 10 times with progressive delay

use DiePHP\Perhaps\Facades\Perhaps;
use DiePHP\Sequences\RandSequence;

Perhaps::retry(function() {
    // Your logic here
}, 10, new RandSequence(1000000, 90000000));

use DiePHP\Perhaps\Facades\Perhaps;
use DiePHP\Sequences\ExponentialSequence;

Perhaps::retry(function() {
    // Your logic here
}, 10, new ExponentialSequence(10, 100));

Perhaps::retry(function($attempt) {
    if ($attempt < 3) {
        throw new \Exception("Simulated failure");
    }
    // Successful operation
    echo "Success on attempt $attempt";
}, 5); // Retry 5 times

Perhaps::retry(function () use ($data) {
    History::create($data); // example
}, 3, new LogarithmicSequence(1000000, 70));
sh
    php artisan vendor:publish --tag=perhaps