# tp6 限流插件 **Repository Path**: cianyi/Tp6flowrestrrictions ## Basic Information - **Project Name**: tp6 限流插件 - **Description**: tp6 限流插件 - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 2 - **Created**: 2023-06-20 - **Last Updated**: 2025-05-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: PHP, ThinkPHP, 限流 ## README ThinkPHP 6.0 限流插件 =============== > 运行环境要求PHP7.2+ 并且需要配置redis缓存驱动 ## 主要新特性 ## 安装 ~~~ composer require cianyi/tp6flowrestrrictions=1.0.1 ~~~ ## 使用方法 说明:支持四种策略SpeedCounter(计数限流),SlideTimeWindow(滑动窗口),LeakyBucket(漏桶),TokenBucket(令牌桶) -------------- * 计数限流 ~~~ setLimitTime(60) //最大请求数 ->setMaxCount(60) ->algorithm(); if (!$result){ #接口请求数达到最大限制 } } } ~~~ * 滑动窗口 ~~~ setLimitTime(60) //最大请求数 ->setMaxCount(60) ->algorithm(); if (!$result){ #接口请求数达到最大限制 } } } ~~~ * 漏桶 ~~~ setBurst(60) //每秒放行请求数 ->setRate(1) ->algorithm(); if (!$result){ #接口请求数达到最大限制 } } } ~~~ * 令牌桶 ~~~ setBurst(60) //每秒增加空闲请求数 ->setRate(1) ->algorithm(); if (!$result){ #接口请求数达到最大限制 } } } ~~~ ## 版权信息 请查阅 [LICENSE](https://gitee.com/cianyi/Tp6flowrestrrictions/blob/master/LICENSE)