当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 供货紧张!苹果被曝 iPhone 12 电源芯片产能不足
- Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
- 华为在5G手机市场占据绝对优势,市调机构对小米的市占出现分歧
- Android Basics - check box
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- 蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
- Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
- Harbor项目高手问答及赠书活动
- 新型存算一体芯片诞生,利好人工智能应用~
- Implementation of verification code recognition in Python opencv pytesseract
猜你喜欢

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

Enabling education innovation and reconstruction with science and technology Huawei implements education informatization

Analysis of istio access control

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

C language I blog assignment 03

Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service

浅谈单调栈

分布式文档存储数据库之MongoDB基础入门

蘑菇街电商交易平台服务架构及改造优化历程(含PPT)

wanxin finance
随机推荐
原创 | 数据资产确权浅议
用科技赋能教育创新与重构 华为将教育信息化落到实处
Android Basics - check box
Python基础语法
Tencent, which is good at to C, how to take advantage of Tencent's cloud market share in these industries?
AQS解析
Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
【Python 1-6】Python教程之——数字
Flink从入门到真香(10、Sink数据输出-Elasticsearch)
TiDB 性能竞赛 11.02-11.06
The network adapter could not establish the connection
This year's salary is 35W +! Why is the salary of Internet companies getting higher and higher?
C language I blog assignment 03
打工人,打工魂,抽终身会员,成为人上人!
Tight supply! Apple's iPhone 12 power chip capacity exposed
漫画:寻找股票买入卖出的最佳时机(整合版)
WLAN 直连(对等连接或 P2P)调研及iOS跨平台调研
阿里撕下电商标签
On DSA of OpenGL

