{"id":22330879,"url":"https://github.com/flavioheleno/interrupt","last_synced_at":"2025-07-29T19:33:04.605Z","repository":{"id":174668926,"uuid":"652586685","full_name":"flavioheleno/interrupt","owner":"flavioheleno","description":"PSR-18 compliant Circuit Breaker wrapper","archived":false,"fork":false,"pushed_at":"2024-03-11T16:55:56.000Z","size":48,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-13T03:46:05.512Z","etag":null,"topics":["circuit-breaker","circuit-breaker-pattern","failure-handling","guzzle-middleware","http-client","php","psr-18"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flavioheleno.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-06-12T11:29:49.000Z","updated_at":"2024-03-11T16:57:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"62794fba-6210-425f-9c73-2a9faebdcc6c","html_url":"https://github.com/flavioheleno/interrupt","commit_stats":null,"previous_names":["flavioheleno/interrupt"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavioheleno%2Finterrupt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavioheleno%2Finterrupt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavioheleno%2Finterrupt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavioheleno%2Finterrupt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flavioheleno","download_url":"https://codeload.github.com/flavioheleno/interrupt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228041258,"owners_count":17860221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circuit-breaker","circuit-breaker-pattern","failure-handling","guzzle-middleware","http-client","php","psr-18"],"created_at":"2024-12-04T04:08:27.322Z","updated_at":"2024-12-04T04:08:27.985Z","avatar_url":"https://github.com/flavioheleno.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Interrupt - Uninterrupted Reliability for HTTP Requests\n\nThis library implements a PSR-18 compliant Circuit Breaker wrapper that can be used to ensure service stability and\nprevent overload or degradation in remote service calls.\n\n## Acknowledgement\n\nThis library is heavily inspired by:\n\n* [ackintosh/ganesha](https://github.com/ackintosh/ganesha)\n* [PrestaShop/circuit-breaker](https://github.com/PrestaShop/circuit-breaker)\n\n## Installation\n\nTo use Interim, install it using composer:\n\n```bash\ncomposer require flavioheleno/interrupt\n```\n\n## Usage\n\n### As a PSR-18 HTTP Client Wrapper\n\n```php\n// any PSR-18 compliant HTTP Client implementation\n// $httpClient = new ...\n\n// resolves the service name to its scheme + host + port\n// eg. https://api.example.org/v1 -\u003e https://api.example.org\n// eg. https://api.example.org:5000/v1 -\u003e https://api.example.org:5000\n// can be replaced by StaticNameResolver\n$serviceNameResolver = Interrupt\\ServiceNameResolvers\\UriBasedResolver();\n\n// any PSR-6 compliant Cache Item Pool implementation\n// $cacheItemPool = new ...\n\n// any PSR-20 compliant Clock implementation\n// $clock = new ...\n\n// can be replaced by FixedTimeWindowBasedRecordStrategy\n$recordStrategy = new Interrupt\\RecordStrategies\\SlidingTimeWindowBasedRecordStrategy(\n  $clock\n);\n\n// can be replaced by CountBasedCircuitBreaker\n$circuitBreaker = new Interrupt\\CircuitBreakers\\RateBasedCircuitBreaker(\n  $clock,\n  $cacheItemPool,\n  $recordStrategy\n);\n\n$failureDetector = new Interrupt\\FailureDetectors\\HttpStatusBasedFailureDetector();\n\n$client = new Psr18Wrapper(\n  $httpClient,\n  $serviceNameResolver,\n  $circuitBreaker,\n  $failureDetector\n);\n\n// when the called service is unavailable, $client will throw an\n// Interrupt\\Exceptions\\ServiceUnavailableException exception.\n```\n\n### As a Guzzle Middleware\n\n```php\n$middleware = new GuzzleMiddleware(\n  $serviceNameResolver,\n  $circuitBreaker,\n  $failureDetector\n);\n\n$handlerStack = \\GuzzleHttp\\HandlerStack::create();\n$handlerStack-\u003epush($middleware);\n\n$client = new GuzzleHttp\\Client(['handler' =\u003e $handlerStack]);\n\n// when the called service is unavailable, $client will throw an\n// Interrupt\\Exceptions\\ServiceUnavailableException exception.\n```\n\n## Components\n\nInterrupt is built around the concept of components to allow easy integration with different environments or frameworks,\nmaking it a flexible and customizable library.\n\n### Service Name Resolver\n\nTo keep track of services accessed by the wrapped client, Interrupt uses the concept of\n[Service Name Resolvers](src/Contracts/ServiceNameResolverInterface.php), that generates consistent service names\nbased on request attributes.\n\nInterrupt is distributed with:\n\n* [UriBasedResolver](src/ServiceNameResolvers/UriBasedResolver.php), a resolver implementation that generates service\nnames from the request URI components\n* [StaticNameResolver](src/ServiceNameResolvers/StaticNameResolver.php), a resolver implementation that always return a\nconstant service name\n\n### Record Strategy\n\nThe [Record Strategy](src/Contracts/RecordStrategyInterface.php) determines how Interrupt keeps track of failure events\nduring a period of time.\n\nA [FixedTimeWindowBasedRecordStrategy](src/RecordStrategies/FixedTimeWindowBasedRecordStrategy.php) that uses a\npredefined time interval to register failure records within its duration. Once the interval is over, the recorded\nfailures are cleaned up and a new fixed interval starts.\n\nA [SlidingTimeWindowBasedRecordStrategy](src/RecordStrategies/SlidingTimeWindowBasedRecordStrategy.php) that uses a\nmoving or shifting time interval to register failure records. Instead of fixed intervals, the time window slides (or\nmoves along) with the failure stream.\n\nThe *Sliding Time Window* approach allows for continuous analysis of the most recent data while still considering a\nspecific timeframe.\n\n\u003e [!NOTE]\n\u003e Both strategies require a [PSR-20](https://www.php-fig.org/psr/psr-20/) compatible Clock implementation.\n\n### Failure Detector\n\nFailure can be subjective to context so Interrupt relies on [Failure Detector](src/Contracts/FailureDetectorInterface.php)\nto detect context-dependant failures.\n\nEmbedded in [Psr18Wrapper](src/Psr18Wrapper.php) is the failure detection for network issues, timeouts and any other\nthrown exception that extends `Psr\\Http\\Client\\ClientExceptionInterface`.\n\nIn addition to that, the [HttpStatusBasedFailureDetector](src/FailureDetectors/HttpStatusBasedFailureDetector.php)\ninterprets the HTTP Status Code as signal of failure.\n\n### Circuit Breakers\n\nInterrupt comes with two [Circuit Breakers](src/Contracts/CircuitBreakerInterface.php) implementations:\n\nA [CountBasedCircuitBreaker](src/CircuitBreakers/CountBasedCircuitBreaker.php) that monitors the number of failures\nrecorded and automatically interrupts the flow of requests if the threshold is exceeded.\n\nA [RateBasedCircuitBreaker](src/CircuitBreakers/RateBasedCircuitBreaker.php) that monitors the rate or frequency of\nfailures recorded and automatically interrupts the flow of requests if the error rate surpasses a predefined threshold.\n\n\u003e [!NOTE]\n\u003e Both circuit breakers require a [PSR-6](https://www.php-fig.org/psr/psr-6/) compatible Cache implementation.\n\n## License\n\nThis library is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflavioheleno%2Finterrupt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflavioheleno%2Finterrupt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflavioheleno%2Finterrupt/lists"}