【发布时间】:2017-10-27 09:17:48
【问题描述】:
我正在编写大量 API 来获取和存储数据。
我喜欢默认的throttle 选项:
protected $middlewareGroups = [
'api' => [
'throttle:60,1',
'bindings',
],
];
将请求限制为每分钟 60 个;但是对于某些路线(es:POST),我想增加这个值。
我尝试在路由中间件上设置'throttle:500,1',如下所示:
Route::group(function () {
Route::get('semaphore/1', ['uses' => 'App\Api\V1\DBs\SemaphoreController@index']);
Route::post('semaphore/1', ['uses' => 'App\Api\V1\DBs\SemaphoreController@store', 'middleware' => 'WriteToDatabaseMiddleware', 'throttle:500,1']);
});
但它不起作用。
有什么想法吗?
谢谢。
更新:
我注意到api.php 路由中使用的'throttle:500,1' 将在Kernel.php 文件中指定的默认'throttle:60,1' 之后设置;然后,它不起作用。
记录流程执行,第一次调用是:
Illuminate\Routing\Middleware\ThrottleRequests -> handle
来自Kernel.php 有maxAttempts=60。
那么,第二次调用是:
Illuminate\Routing\Middleware\ThrottleRequests -> handle
来自api.php 有maxAttempts=500。
换句话说,api.php 文件中的throttle:500,1 不会覆盖Kernel.php 文件中的throttle:60,1。
【问题讨论】:
标签: php laravel-5.4 throttling