Laravel 5.5 ThrottleRequest Proportional Software

Does anyone have information on how to implement the ThrottleRequest middleware in Laravel 5.5?

I do not quite understand the meaning of the decayMinutes parameter in particular: https://laravel.com/api/5.5/Illuminate/Routing/Middleware/ThrottleRequests.html

I understand how to apply it to a route, I just donโ€™t know what options can be reaosnable.

+5
source share
2 answers

decayMinutes - time within your limit will be calculated. Technically, the limit is a value with TTL (Time To Live) $decayMinutes * 60 secs in the cache, which increases with each hit. When the TTL value exceeds the value, it will be automatically destroyed in the cache, and the counting of new views will begin.

Check out the code RateLimit :: hit () . This is pretty clear:

 /** * Increment the counter for a given key for a given decay time. * * @param string $key * @param float|int $decayMinutes * @return int */ public function hit($key, $decayMinutes = 1) { $this->cache->add( $key.':timer', $this->availableAt($decayMinutes * 60), $decayMinutes ); $added = $this->cache->add($key, 0, $decayMinutes); $hits = (int) $this->cache->increment($key); if (! $added && $hits == 1) { $this->cache->put($key, 1, $decayMinutes); } return $hits; } 

If you want to limit activity to 10 beats in 5 minutes, than decayMinutes should be 5.

+2
source

I understand decayMinutes as holding time. For intance, if you want to give 10 login attempts with the wrong password, but if he tries 11 times, the user will be blocked for the number of minutes specified in decayMinutes . If you specify 10 minutes as decayMinutes , the user will be blocked for 10 minutes

+6
source

Source: https://habr.com/ru/post/1272578/


All Articles