当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 为 Docsify 自动生成 RSS 订阅
- 阿里撕下电商标签
- Q & A and book giving activities of harbor project experts
- 喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
- Eight ways to optimize if else code
- Written interview topic: looking for the lost pig
- 软件开发中如何与人协作? | 每日趣闻
- How to cooperate with people in software development? |Daily anecdotes
- 为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
猜你喜欢

Major changes in Huawei's cloud: Cloud & AI rises to Huawei's fourth largest BG with full fire

漫画:寻找股票买入卖出的最佳时机(整合版)

如何将 PyTorch Lightning 模型部署到生产中

Interpretation of deepmind's latest paper: the causal reasoning algorithm in discrete probability tree is proposed for the first time

The most complete! Alibaba economy cloud original practice! (Internet disk link attached)

我们做了一个医疗版MNIST数据集,发现常见AutoML算法没那么好用

为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新

应届生年薪35w+ !倒挂老员工,互联网大厂薪资为何越来越高?

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

阿里云视频云技术专家 LVS 演讲全文:《“云端一体”的智能媒体生产制作演进之路》
随机推荐
What can your cloud server do? What is the purpose of cloud server?
TiDB 性能竞赛 11.02-11.06
Ubuntu20.04 access FTP server garbled problem + upload files
OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
重返全球第三,小米做对了什么?
用科技赋能教育创新与重构 华为将教育信息化落到实处
Hematemesis! Alibaba Android Development Manual! (Internet disk link attached)
Workers, workers soul, draw lifelong members, become a person!
Istio流量管理--Ingress Gateway
The progress bar written in Python is so wonderful~
How to write a resume and project
Enabling education innovation and reconstruction with science and technology Huawei implements education informatization
金融领域首个开源中文BERT预训练模型,熵简科技推出FinBERT 1.0
Android Basics - check box
The network adapter could not establish the connection
Written interview topic: looking for the lost pig
[Python 1-6] Python tutorial 1 -- number
如何将 PyTorch Lightning 模型部署到生产中
Suitable for C / C + + novice learning some projects, do not give me to miss!
阿里撕下电商标签

