ella123/hyperf-throttle

hyperf throttle rate limit

3.1.14 2024-05-31 12:42 UTC

This package is auto-updated.

Last update: 2024-10-31 00:41:12 UTC


README

适配 hyperf 框架的请求频率限流器。

安装依赖

composer require ella123/hyperf-throttle

发布配置

php bin/hyperf.php vendor:publish ella123/hyperf-throttle

注解说明

使用实例

  • 支持类
  • 支持方法
/**
 * 频率限制
 */
#[\Ella123\HyperfThrottle\Annotation\Throttle(limit: 60,timer: 60)]
class A {
    #[\Ella123\HyperfThrottle\Annotation\Throttle(limit: 60,timer: 60)] 
    public function name() {
    }
}

/**
 * 重复提交
 */
#[\Ella123\HyperfThrottle\Annotation\Resubmit(limit: 1,timer: 60)]
class B {
    #[\Ella123\HyperfThrottle\Annotation\Resubmit(limit: 1,timer: 60)]
    public function submit() {
    }
}

/**
 * 短信限制(支持定义不同规则)
 */
#[\Ella123\HyperfThrottle\Annotation\SmsMinuteLimit(limit: 1,timer: 60)]
#[\Ella123\HyperfThrottle\Annotation\SmsHourLimit(limit: 5,timer: 3600)]
#[\Ella123\HyperfThrottle\Annotation\SmsDayLimit(limit: 15,timer: 86400)]
class C {
    #[\Ella123\HyperfThrottle\Annotation\SmsMinuteLimit(limit: 1,timer: 60)]
    #[\Ella123\HyperfThrottle\Annotation\SmsHourLimit(limit: 5,timer: 3600)]
    #[\Ella123\HyperfThrottle\Annotation\SmsDayLimit(limit: 15,timer: 86400)]
    public function send() {
    }
}