Download the PHP package yzh52521/webman-throttle without Composer
On this page you can find all versions of the php package yzh52521/webman-throttle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download yzh52521/webman-throttle
More information about yzh52521/webman-throttle
Files in yzh52521/webman-throttle
Download yzh52521/webman-throttle
More information about yzh52521/webman-throttle
Files in yzh52521/webman-throttle
Please rate this library. Is it a good library?
Informations about the package webman-throttle
webman-throttle
作用
通过本中间件可限定用户在一段时间内的访问次数,可用于保护接口防爬防爆破的目的。
安装
安装后会自动为项目生成 config/plugin/yzh52521/throttle/app.php (注意:任何时候你都不应该修改最后一行的 hash注释)配置文件,安装后组件不会自动启用,需要手动设置。
开启
插件以中间件的方式进行工作,因此它的开启与其他中间件一样,例如在全局中间件中使用:
配置说明
当配置项满足以下条件任何一个时,不会限制访问频率:
其中 key 用来设置缓存键的, 而 visit_rate 用来设置访问频率,单位可以是秒,分,时,天。例如:1/s, 10/m, 98/h, 100/d , 也可以是 100/600 (600 秒内最多 100 次请求)。
灵活定制
示例一:针对用户个体做限制,key的值可以设为函数,该函数返回新的缓存键值(需要Session支持),例如:
实例二:在回调函数里针对不同控制器和方法定制生成key,中间件会进行转换:
示例三:在闭包内修改本次访问频率或临时更换限流策略:(PS:此示例需要本中间件在路由中间件后启用,这样预设的替换功能才会生效。)
示例四:在路由中独立配置
注意:
1、Webman-framework >= 1.3.16 支持路由向中间件传参 使用 $route->param() 方法
2、禁止访问时,throttle 默认是抛出 HttpResponseException, 当前插件场景下将正常响应一个httpResponse(即不会主动:Throw Exception),特殊需求请在 "visit_fail_response" 匿名函数中配置
申明
All versions of webman-throttle with dependencies
PHP Build Version
Package Version
The package yzh52521/webman-throttle contains the following files
Loading the files please wait ....