当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Essential for back-end programmers: distributed transaction Basics
- wanxin finance
- Hematemesis! Alibaba Android Development Manual! (Internet disk link attached)
- Python basic syntax
- Stm32uberide download and install - GPIO basic configuration operation - debug (based on CMSIS DAP debug)
- C language I blog assignment 03
- 后端程序员必备:分布式事务基础篇
- PMP考试通过心得分享
- 华为在5G手机市场占据绝对优势,市调机构对小米的市占出现分歧
- Don't look! Full interpretation of Alibaba cloud's original data lake system! (Internet disk link attached)
猜你喜欢
Flink从入门到真香(6、Flink实现UDF函数-实现更细粒度的控制流)
最全!阿里巴巴经济体云原生实践!(附网盘链接)
Automatically generate RSS feeds for docsify
PMP心得分享
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
漫画|讲解一下如何写简历&项目
金融领域首个开源中文BERT预训练模型,熵简科技推出FinBERT 1.0
Rust : 性能测试criterion库
阿里撕下电商标签
11 server monitoring tools commonly used by operation and maintenance personnel
随机推荐
Understanding design patterns
What is the database paradigm
What can your cloud server do? What is the purpose of cloud server?
Xamarin 从零开始部署 iOS 上的 Walterlv.CloudKeyboard 应用
BCCOIN告诉您:年底最靠谱的投资项目是什么!
Istio流量管理--Ingress Gateway
The network adapter could not establish the connection
“他,程序猿,35岁,被劝退”:不要只懂代码,会说话,胜过10倍默默努力
C language I blog assignment 03
Rabbitmq (1) - basic introduction
Flink从入门到真香(7、Sink数据输出-文件)
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
Python basic syntax variables
谷歌开源能翻译101种语言的AI模型,只比Facebook多一种
入门级!教你小程序开发不求人(附网盘链接)
Don't look! Full interpretation of Alibaba cloud's original data lake system! (Internet disk link attached)
2035我们将建成这样的国家
你的云服务器可以用来做什么?云服务器有什么用途?
Returning to the third place in the world, what did Xiaomi do right?
On DSA of OpenGL