VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • [PHP] 解决laravel 报错:Too Many Attempts

当使用ab测试工具测试接口的时候

在日志里看到了很多Too Many Attempts的错误

 

这是因为laravel的限流中间件在起作用

api路由组默认就有在使用限流中间件

app/Http/Kernel.php

1
2
3
4
'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次
 

出处:https://www.cnblogs.com/taoshihan/p/15149713.html

相关教程