{"id":15027146,"url":"https://github.com/teodoroleckie/circuit-breaker","last_synced_at":"2026-04-06T00:01:50.357Z","repository":{"id":57070503,"uuid":"368892136","full_name":"teodoroleckie/circuit-breaker","owner":"teodoroleckie","description":"⚡ With the powerful Circuit Breaker library you will be able to manage and protect your application from requests that stop working to avoid overloads. The implementation that you will have to do is very simple.","archived":false,"fork":false,"pushed_at":"2021-05-23T11:33:48.000Z","size":63,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-31T16:46:49.733Z","etag":null,"topics":["circuit-breaker","microservice","microservices-architecture","php","php-8","php-circuit-breaker","php8","tleckie"],"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/teodoroleckie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["teodoroleckie"],"custom":["https://www.paypal.com/donate?business=ZHYA2MTGA4884\u0026currency_code=USD"]}},"created_at":"2021-05-19T14:11:27.000Z","updated_at":"2023-04-04T16:19:27.000Z","dependencies_parsed_at":"2022-08-24T10:41:17.092Z","dependency_job_id":null,"html_url":"https://github.com/teodoroleckie/circuit-breaker","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/teodoroleckie/circuit-breaker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Fcircuit-breaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Fcircuit-breaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Fcircuit-breaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Fcircuit-breaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teodoroleckie","download_url":"https://codeload.github.com/teodoroleckie/circuit-breaker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Fcircuit-breaker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31454200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"ssl_error","status_checked_at":"2026-04-05T21:22:51.943Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","microservice","microservices-architecture","php","php-8","php-circuit-breaker","php8","tleckie"],"created_at":"2024-09-24T20:05:51.281Z","updated_at":"2026-04-06T00:01:50.274Z","avatar_url":"https://github.com/teodoroleckie.png","language":"PHP","funding_links":["https://github.com/sponsors/teodoroleckie","https://www.paypal.com/donate?business=ZHYA2MTGA4884\u0026currency_code=USD"],"categories":[],"sub_categories":[],"readme":"# PHP Circuit Breaker \n\nWith the powerful Circuit Breaker library you will be able to manage and protect your application from requests that stop working to avoid overloads. The implementation that you will have to do is very simple.\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/teodoroleckie/circuit-breaker/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/circuit-breaker/?branch=main)\n[![Build Status](https://scrutinizer-ci.com/g/teodoroleckie/circuit-breaker/badges/build.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/circuit-breaker/build-status/main)\n[![Code Intelligence Status](https://scrutinizer-ci.com/g/teodoroleckie/circuit-breaker/badges/code-intelligence.svg?b=main)](https://scrutinizer-ci.com/code-intelligence)\n\n\n# Installation:\n\nYou can install the package via composer:\n\n```bash\ncomposer require tleckie/circuit-breaker\n```\n\nIt's common for software systems to make remote calls to software running in different processes, probably on different \nmachines across a network. One of the big differences between in-memory calls and remote calls is that remote calls can \nfail, or hang without a response until some timeout limit is reached. What's worse if you have many callers on a \nunresponsive supplier, then you can run out of critical resources leading to cascading failures across multiple systems. \nIn his excellent book Release It, Michael Nygard popularized the Circuit Breaker pattern to prevent this kind of \ncatastrophic cascade.\n\nThe basic idea behind the circuit breaker is very simple. You wrap a protected function call in a circuit breaker object, \nwhich monitors for failures. Once the failures reach a certain threshold, the circuit breaker trips, and all further \ncalls to the circuit breaker return with an error, without the protected call being made at all. \nUsually you'll also want some kind of monitor alert if the circuit breaker trips.\n\n\nCircuit breaker is heavily used in microservice architecture to find issues between microservices calls.\nThe main idea is to protect your code from making unnecessary calls if the microservice you call is down.\n\n# Features:\n- Automatic update. (i.e you don't have to manually add success or failure method like other library)\n- Return result from the protected function.\n- Retry timeout.\n- Protect your services calls if they are dropped.\n\n# Usage:\n\n- You have to create an instance of the CircuitBreaker class with three arguments.\nThe first must be an instance of your preferred psr-16 cache, it must implement the Psr\\SimpleCache\\CacheInterface \ninterface and is not included with this library.  \n- The second required argument is the number of retries the library must do before entering the open state.  \n- The third argument is the time in seconds that the circuit must wait before making new calls to the protected service.\n- The CircuitBreaker class makes available the callService method in which a closure must be implemented to call the service from within.\n- Within the closure, the exception that would be fired when the service is not operational must be controlled, \n  said exception is caught and a CircuitBreakerException exception is created, passing through its constructor the one that has been handled.\n- At this point, the service is fully protected against failure.\n- When CircuitBreaker goes to the open state, that is, the service is not functional, it will stop receiving requests \n  by throwing the last known exception in all cases until the service is available to receive new requests.\n- The whole process is transparent and automatic for you.  \n- Given the nature of the microservices' architecture, it is recommended to use a centralized cache storage shared between all your frontend and backend machines.\n\n```php\n\u003c?php\nrequire \"vendor/autoload.php\";\n\nuse Tleckie\\CircuitBreaker\\CircuitBreaker;\nuse Tleckie\\CircuitBreaker\\Exception\\CircuitBreakerException;\n\n\n$circuitBreaker = new CircuitBreaker(\n    // Psr\\SimpleCache\\CacheInterface object, not included with this library.\n    new SimpleCacheAdapter( ... ),\n    3, // maxFailures\n    60 // retryTimeout\n);\n\n// create your service instance\n$service = new MyUserService( ... );\n\n$serviceResponse = $circuitBreaker-\u003ecallService(\n\n    static function () use ($service) {\n        try {\n\n            return $service-\u003eusers();\n\n        } catch (ServiceTimeOutException $exception) {\n            throw new CircuitBreakerException($exception);\n        }\n\n    },\n    'my.user.service'\n);\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteodoroleckie%2Fcircuit-breaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteodoroleckie%2Fcircuit-breaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteodoroleckie%2Fcircuit-breaker/lists"}