当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- How to write a resume and project
- Flink from introduction to Zhenxiang (7. Sink data output file)
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Flink: from introduction to Zhenxiang (6. Flink implements UDF function - realizes more fine-grained control flow)
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- 为 Docsify 自动生成 RSS 订阅
- python基本语法 变量
- Bccoin tells you: what is the most reliable investment project at the end of the year!
- Drink soda, a bottle of soda water 1 yuan, two empty bottles can change a bottle of soda, give 20 yuan, how much soda can you
- Tidb performance competition 11.02-11.06
猜你喜欢

C language I blog assignment 03

重返全球第三,小米做对了什么?

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

啥是数据库范式

Implementation of verification code recognition in Python opencv pytesseract

Flink从入门到真香(6、Flink实现UDF函数-实现更细粒度的控制流)

Python basic syntax

金融领域首个开源中文BERT预训练模型,熵简科技推出FinBERT 1.0

Tencent, which is good at to C, how to take advantage of Tencent's cloud market share in these industries?

10个常见的软件架构模式
随机推荐
Xamarin 从零开始部署 iOS 上的 Walterlv.CloudKeyboard 应用
How to solve the difference between NAT IP and port IP
Q & A and book giving activities of harbor project experts
【Python 1-6】Python教程之——数字
新型存算一体芯片诞生,利好人工智能应用~
小米、OPPO在欧洲市场继续飙涨,小米更是直逼苹果
Flink: from introduction to Zhenxiang (3. Reading data from collection and file)
Windows10关机问题----只有“睡眠”、“更新并重启”、“更新并关机”,但是又不想更新,解决办法
Written interview topic: looking for the lost pig
On monotonous stack
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
一文读懂机器学习“数据中毒”
“他,程序猿,35岁,被劝退”:不要只懂代码,会说话,胜过10倍默默努力
Win10 terminal + WSL 2 installation and configuration guide, exquisite development experience
Flink从入门到真香(7、Sink数据输出-文件)
This paper analyzes the top ten Internet of things applications in 2020!
打工人,打工魂,抽终身会员,成为人上人!
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Rust : 性能测试criterion库
It's worth seeing! EMR elastic low cost offline big data analysis best practice (with network disk link)

