[PHP] 解决laravel 报错:Too Many Attempts
当使用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次
十年开发经验程序员,离职全心创业中,历时三年开发出的产品《唯一客服系统》
一款基于Golang+Vue开发的在线客服系统,软件著作权编号:2021SR1462600。一套可私有化部署的网站在线客服系统,编译后的二进制文件可直接使用无需搭开发环境,下载zip解压即可,仅依赖MySQL数据库,是一个开箱即用的全渠道在线客服系统,致力于帮助广大开发者/公司快速部署整合私有化客服功能。
开源地址:唯一客服(开源学习版)
官网地址:唯一客服官网