当前位置:网站首页>Improvement of rate limit for laravel8 update
Improvement of rate limit for laravel8 update
2020-11-08 13:07:00 【Shenbing general】
Original address :https://www.wjcms.net/archives/laravel8%E6%9B%B4%E6%96%B0%E4%B9%8B%E9%80%9F%E7%8E%87%E9%99%90%E5%88%B6%E6%94%B9%E8%BF%9B
Laravel The request rate limiter for has been enhanced , More flexibility and functionality , At the same time, it remains the same as the previous version of throttle middleware API Backward compatibility .
The rate limiter is used RateLimiter Facade for Method defined . The for Method accepts a rate limiter name and a Closure, The Closure Returns the limit configuration that should be applied to the route to which the rate limiter is assigned :
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for('global', function (Request $request) {
return Limit::perMinute(1000);
});
Since the rate limiter callback receives the incoming HTTP Request instance , So you can dynamically build appropriate rate limits based on incoming requests or authenticated users :
RateLimiter::for('uploads', function (Request $request) {
return $request->user()->vipCustomer()
? Limit::none()
: Limit::perMinute(100);
});
Sometimes you may want to subdivide the rate limit by any value . for example , You may want to allow users to each IP Address every minute 100 Access to the given route . So , You can by Use the following method when establishing the rate limit :
RateLimiter::for('uploads', function (Request $request) {
return $request->user()->vipCustomer()
? Limit::none()
: Limit::perMinute(100)->by($request->ip());
});
have access to throttle Middleware attaches a rate limiter to a route or routing group . The throttle middleware accepts the name of the rate limiter that you want to assign to the route :
Route::middleware(['throttle:uploads'])->group(function () {
Route::post('/audio', function () {
//
});
Route::post('/video', function () {
//
});
});
版权声明
本文为[Shenbing general]所创,转载请带上原文链接,感谢
边栏推荐
- TiDB 性能竞赛 11.02-11.06
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- Tight supply! Apple's iPhone 12 power chip capacity exposed
- 数据库连接报错之IO异常(The Network Adapter could not establish the connection)
- rabbitmq(一)-基础入门
- 小米、OPPO在欧洲市场继续飙涨,小米更是直逼苹果
- 解析Istio访问控制
- Istio流量管理--Ingress Gateway
- Rust: performance test criteria Library
- Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
猜你喜欢

Tight supply! Apple's iPhone 12 power chip capacity exposed

Python basic syntax variables

后端程序员必备:分布式事务基础篇

漫画|讲解一下如何写简历&项目

Rust: performance test criteria Library

Bccoin tells you: what is the most reliable investment project at the end of the year!

Written interview topic: looking for the lost pig

2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...

在51CTO学院Get到PMP证书

On the confirmation of original data assets
随机推荐
This paper analyzes the top ten Internet of things applications in 2020!
How to cooperate with people in software development? |Daily anecdotes
Bccoin tells you: what is the most reliable investment project at the end of the year!
[Python 1-6] Python tutorial 1 -- number
Harbor项目高手问答及赠书活动
C语言I博客作业03
金融领域首个开源中文BERT预训练模型,熵简科技推出FinBERT 1.0
喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
android基础-CheckBox(复选框)
How to solve the difference between NAT IP and port IP
Suitable for C / C + + novice learning some projects, do not give me to miss!
蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
适合c/c++新手学习的一些项目,别给我错过了!
AQS analysis
On monotonous stack
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
It's worth seeing! EMR elastic low cost offline big data analysis best practice (with network disk link)
STM32CubeIDE下载安装-GPIO基本配置操作-Debug调试(基于CMSIS DAP Debug)
我们做了一个医疗版MNIST数据集,发现常见AutoML算法没那么好用

