PHP code example of yupmin / laravel-phystrix

1. Go to this page and download the library: Download yupmin/laravel-phystrix 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/ */

    

yupmin / laravel-phystrix example snippets


class TestCommand extends AbstractCommand
{
    protected $wantFallback;

    public function __construct($wantFallback = false)
    {
        $this->wantFallback = $wantFallback;
    }

    /**
     * @param bool $wantFallback
     * @return mixed
     * @throws Exception
     */
    protected function run()
    {
        if ($this->wantFallback) {
            throw new Exception("fallback");
        }

        return 'run test';
    }

    /**
     * @param Exception|null $exception
     * @return mixed
     */
    protected function getFallback(?Exception $exception = null)
    {
        return $exception->getMessage();
    }
}

phystrinx(App\Phystrix\TestCommand::class)->execute();
// => "run test"
phystrinx(App\Phystrix\TestCommand::class, false)->execute();
// => "fallback"

Route::get('/phystrix.stream', function () {
    phystrix_stream()->run();
});
bash
php artisan vendor/publish --provider=Yupmin\Phystrix\ServiceProvider
bash
php artisan make:phystrix-command TestCommand