All Projects → loveOSS → resiliency

loveOSS / resiliency

Licence: MIT license
A modern PHP library that allows you to make resilient calls to external services 🔁

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to resiliency

php-json-schema-model-generator
Creates (immutable) PHP model classes from JSON-Schema files including all validation rules as PHP code
Stars: ✭ 36 (-54.43%)
Mutual labels:  php8, php74
docker-lemp
A single container LEMP complete fullstack with latest release of PHP7.4.33, 8.0.26 & 8.1.13/8.2RC and MySQL, nginx, PostgreSQL, phalcon, swoole, mailcatcher, beanstalkd, elasticsearch, memcached, redis, adminer and all you ever need; on top alpine3.15
Stars: ✭ 106 (+34.18%)
Mutual labels:  php8, php74
php-currency-api
Standardized wrapper for popular currency rate APIs. Currently supports FixerIO, CurrencyLayer, Open Exchange Rates and Exchange Rates API.
Stars: ✭ 17 (-78.48%)
Mutual labels:  php8, php74
laravel-username-generator
Automatically generate usernames for Laravel User Model
Stars: ✭ 37 (-53.16%)
Mutual labels:  php8, php74
perseverance
Make your functions 💪 resilient and 🚥 fail-fast to 💩 failures or ⌚ delays
Stars: ✭ 12 (-84.81%)
Mutual labels:  resiliency, circuit-breaker
Luffy
Luffy is a simple resilience and transient-fault handling library
Stars: ✭ 19 (-75.95%)
Mutual labels:  resiliency, circuit-breaker
Istio
Connect, secure, control, and observe services.
Stars: ✭ 28,970 (+36570.89%)
Mutual labels:  resiliency, circuit-breaker
Semian
🐒 Resiliency toolkit for Ruby for failing fast
Stars: ✭ 976 (+1135.44%)
Mutual labels:  resiliency, circuit-breaker
Phpmetrics
Beautiful and understandable static analysis tool for PHP
Stars: ✭ 2,180 (+2659.49%)
Mutual labels:  quality
log
Aplus Framework Log Library
Stars: ✭ 14 (-82.28%)
Mutual labels:  php8
Jscpd
Copy/paste detector for programming source code.
Stars: ✭ 2,397 (+2934.18%)
Mutual labels:  quality
Constexpr Everything
Rewrite C++ code to automatically apply `constexpr` where possible
Stars: ✭ 178 (+125.32%)
Mutual labels:  quality
php-best-practices
What I consider the best practices for web and software development.
Stars: ✭ 60 (-24.05%)
Mutual labels:  quality
Vividus
Vividus is all in one test automation tool
Stars: ✭ 170 (+115.19%)
Mutual labels:  quality
video-quality-metrics
Test specified presets/CRF values for the x264 or x265 encoder. Compares VMAF/SSIM/PSNR numerically & via graphs.
Stars: ✭ 87 (+10.13%)
Mutual labels:  quality
Jpeek
Java Code Static Metrics (Cohesion, Coupling, etc.)
Stars: ✭ 168 (+112.66%)
Mutual labels:  quality
Coveragechecker
Allows old code to use new standards
Stars: ✭ 159 (+101.27%)
Mutual labels:  quality
istio-talk
A talk on Istio and related demos
Stars: ✭ 11 (-86.08%)
Mutual labels:  resiliency
crypto
Aplus Framework Crypto Library
Stars: ✭ 20 (-74.68%)
Mutual labels:  php8
GCMS
PHP FASTEST CMS with Ajax support
Stars: ✭ 19 (-75.95%)
Mutual labels:  php8

Resiliency, an implementation for resilient and modern PHP applications

codecov PHPStan Psalm Build Status

Main principles

circuit breaker

This library is compatible with PHP 7.4+.

Installation

composer require love-oss/resiliency

Use

You need to configure a system for the Circuit Breaker:

  • the failures: define how many times we try to access the service;
  • the timeout: define how long we wait (in ms) before consider the service unreachable;
  • the stripped timeout: define how long we wait (in ms) before consider the service unreachable, once we're in half open state;
  • the threshold: define how long we wait (in ms) before trying to access again the service;
  • the (HTTP|HTTPS) client that will be used to reach the services;
  • the fallback callback will be used if the distant service is unreachable when the Circuit Breaker is Open (means "is used").

You'd better return the same type of response expected from your distant call.

use Resiliency\MainCircuitBreaker;
use Resiliency\Systems\MainSystem;
use Resiliency\Storages\SimpleArray;
use Resiliency\Clients\SymfonyClient;
use Symfony\Component\HttpClient\HttpClient;

$client = new SymfonyClient(HttpClient::create());

$mainSystem = MainSystem::createFromArray([
    'failures' => 2,
    'timeout' => 100,
    'stripped_timeout' => 200,
    'threshold' => 10000,
], $client);

$storage = new SimpleArray();

// Any PSR-14 Event Dispatcher implementation.
$dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher;

$circuitBreaker = new MainCircuitBreaker(
    $mainSystem,
    $storage,
    $dispatcher
);

/**
 * @var Service $service
 */
$fallbackResponse = function ($service) {
    return '{}';
};

$circuitBreaker->call(
    'https://api.domain.com',
    $fallbackResponse,
    [
        'query' => [
            '_token' => '123456789',
        ]
    ]
);

Clients

Resiliency library supports both Guzzle (v6 & v7) and HttpClient Component from Symfony (v4 & v5).

Monitoring

This library provides a minimalist system to help you monitor your circuits.

$monitor = new SimpleMonitor();

// Collect information while listening
// to some circuit breaker events...
function listener(Event $event) {
    $monitor->add($event);
};

// Retrieve a complete report for analysis or storage
$report = $monitor->getReport();

Tests

composer test

Code quality

This library has high quality standards:

composer cs-fix && composer phpstan && composer psalm && composer phpqa

We also use PHPQA to check the Code quality during the CI management of the contributions:

composer phpqa

I've heard of the PrestaShop Circuit Breaker: what library should I use ?

Welcome, that's an interesting question !

Above all, I must say that I'm the former author of the PrestaShop Circuit Breaker library and I have decided to fork my own library to be able to improve it without the constraints of the PrestaShop CMS main project.

As of now (June, 2021), these libraries have a lot in common !

They share almost the same API, and the PrestaShop Core Team have created multiple implementations of Circuit Breaker interface and Factory :

  • SimpleCircuitBreaker
  • AdvancedCircuitBreaker
  • PartialCircuitBreaker
  • SymfonyCircuitBreaker
  1. They maintain a version compatible with PHP 7.2+ and Symfony 4 but not (yet ?) with PHP 8 and Symfony 5 ;
  2. They have a dependency on their own package named php-dev-tools ;
  3. They maintain an implementation of Storage using Doctrine Cache library ;
  4. They don't have a Symfony HttpClient implementation ;
  5. For the events, I'm not sure as their implementation make the list difficult to establish ;
  6. They don't provide a mecanism to reset and restore a Circuit Breaker ;
  7. They don't provide a mecanism to monitor the activity of a Circuit Breaker ;
  8. They have removed Psalm from their CI and they don't use PHPQA ;
  9. They have added declare(strict_types=1); on all the files ;
  10. They don't declare a .gitattributes file, this means that all tests are downloaded when we require their library ;

All right ... but this don't tell me what library should I use in my project !

  • If you need PHP 5.6, use Circuit Breaker v3
  • If you need PHP 7.2, use Circuit Breaker v4
  • If you need PHP 7.4+, use Resiliency
  • If you need a library maintained by a team of developers, use PrestaShop
  • If you trust me to maintain this package almost all alone, use Resiliency !
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].