idealizetecnologia/circuit-breaker-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

idealizetecnologia/circuit-breaker-php

Composer 安装命令:

composer require idealizetecnologia/circuit-breaker-php

包简介

Circuit Breaker for PHP

README 文档

README

Build Status Scrutinizer Code Quality Code Intelligence Status Total Downloads

For more information about this pattern see this.

This implementation has only redis adapter yet

Starting with composer

composer require leocarmo/circuit-breaker-php

Redis adapter

The first argument is a redis connection, the second is your product name, for redis namespace avoid key conflicts with another product using the same redis.

use LeoCarmo\CircuitBreaker\CircuitBreaker;

// Connect to redis
$redis = new \Redis();
$redis->connect('localhost', 6379);

$adapter = new \LeoCarmo\CircuitBreaker\Adapters\RedisAdapter($redis, 'my-product');

// Set redis adapter for CB
CircuitBreaker::setAdapter($adapter);

Set circuit break settings

This is not required, default values ​​will be set

// Configure settings for CB  
CircuitBreaker::setGlobalSettings([  
  'timeWindow' => 60, // Time for an open circuit (seconds)  
  'failureRateThreshold' => 50, // Fail rate for open the circuit  
  'intervalToHalfOpen' => 30, // Half open time (seconds)  
]);

Configure settings for specific service

// Configure settings for specific service
CircuitBreaker::setServiceSettings('my-custom-service', [  
  'timeWindow' => 30, // Time for an open circuit (seconds)  
  'failureRateThreshold' => 15, // Fail rate for open the circuit  
  'intervalToHalfOpen' => 10, // Half open time (seconds)  
]);

Check if circuit is available (closed)

Each check is for a specific service. So you can have multiple services in the same application, and when one circuit is open, the other works normally.

// Check circuit status for service: `my-service`
if (! CircuitBreaker::isAvailable('my-service')) {  
  die('Circuit is not available!');  
}

Record success and failure

// Usage example for success and failure  
try {  
  Service::execute('something');  
  CircuitBreaker::success('my-service');  
} catch (\ServiceException $e) {  
  CircuitBreaker::failure('my-service');  
  die($e->getMessage());  
}

Credits

idealizetecnologia/circuit-breaker-php 适用场景与选型建议

idealizetecnologia/circuit-breaker-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32.41k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 02 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 idealizetecnologia/circuit-breaker-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 idealizetecnologia/circuit-breaker-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 idealizetecnologia/circuit-breaker-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 32.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 29
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-06