问题描述
是否可以通过任何方式自定义速率限制持续时间?
Is there any way through which the rate limit duration can be customized?
例如,我正在使用默认的Laravel速率限制器.我希望有这样的内容-每小时允许10个请求.
For instance, I am using the default Laravel rate limiter.I would want to have something like - allow 10 requests per hour.
推荐答案
Laravel节流阀 是Laravel应用程序的速率限制器.
Laravel throttle is a rate limiter for the Laravel application.
您可以通过以下路由组使您的请求安全地实施laravel节流阀:
You can make your request safe implementing laravel throttle by route group like :
Route::group(['middleware' => 'throttle:10,60'], function () {
Route::get('your_route', 'YourController@your_method');
Route::post('your_route2', 'YourController@your_method2');
});
或
Route::middleware('throttle:10,60')->group(function () {
Route::get('/user', function () {
//
});
});
在单个用户或会话IP的每 60分钟 (1小时)中允许了 10 个请求.您必须在实时服务器上对其进行测试.在本地主机中将无法使用.
Here 10 requests allowed in every 60 minutes (1 hour) by a single user or session IP. You have to test it on a live server. It would not work in localhost.
这篇关于我可以在Laravel中自定义速率限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!