当使用ab测试工具测试接口的时候
在日志里看到了很多Too Many Attempts的错误
这是因为laravel的限流中间件在起作用
api路由组默认就有在使用限流中间件
app/Http/Kernel.php
'api' => ['throttle:api',\Illuminate\Routing\Middleware\SubstituteBindings::class,],
throttle就是限流中间件,:冒号后面的是传递的参数“api”
'throttle:api', 可以把这个去掉
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
protected $routeMiddleware = ['auth' => \App\Http\Middleware\Authenticate::class,'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,'can' => \Illuminate\Auth\Middleware\Authorize::class,'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,];
"api" 就是限流的一个key
app\Providers\RouteServiceProvider.php
protected function configureRateLimiting(){RateLimiter::for('api', function (Request $request) {return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());});}
根据ip限制,每分钟60次