hi-man/rateguardian 问题修复 & 功能扩展

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

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

hi-man/rateguardian

Composer 安装命令:

composer require hi-man/rateguardian

包简介

local rate limit based on yac

README 文档

README

Build Status

keep your server calm down

Requirements

  • php 7.3+
  • yac 2.0.3+

Installation

composer require hi-man/rateguardian

Usage

step 1 : initialize guardian

RateGuardian::getInstance()->guardianOn($key, $total, $ttl)
  • $key the unique guardian key, such as api pathname, not longer than 41 characters
  • $ttl in seconds, a counter will be increased in this period
  • $total the max counter value allowd in $ttl second

step 2 : guard api with guardian key

RateGuardian::getInstance()->guard($key);
  • a false value indicates the api is overloaded, application should handle this situation instead of providing service
  • return value
    • return true if counter less than $total
    • return true if counter equals $total
    • return true if $key does not be registered with guardianOn
    • otherwise return false

step 3 : clear guardian

RateGuardian::getInstance()->guardianOff($key);
  • restart php-fpm or php script also cleared guardian setting

optional: get guardian info

RateGuardian::getInstance()->show($key);
  • return a array of guardian info
    • total the value provided by guardianOn
    • ttl the value provided by guardianOn
    • expired unix timestamp that calculating periods ended
    • current current counter value

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固