有沒有人有關於如何在Laravel 5.5中實現ThrottleRequest
中間件的信息?Laravel 5.5 ThrottleRequest中間件
我不是在decayMinutes
參數的意思很清楚,特別是:https://laravel.com/api/5.5/Illuminate/Routing/Middleware/ThrottleRequests.html
我知道如何將它應用到路線,我只是我不知道什麼reaosnable參數會。
有沒有人有關於如何在Laravel 5.5中實現ThrottleRequest
中間件的信息?Laravel 5.5 ThrottleRequest中間件
我不是在decayMinutes
參數的意思很清楚,特別是:https://laravel.com/api/5.5/Illuminate/Routing/Middleware/ThrottleRequests.html
我知道如何將它應用到路線,我只是我不知道什麼reaosnable參數會。
decayMinutes
- 這是您的限制內的時間將被計數。技術上的限制是緩存中的TTL(生存時間)$decayMinutes * 60
秒的值,每次命中時都會增加。當TTL超過值時,將自動在緩存中銷燬,新的點擊數將啓動。
看看RateLimit::hit()的代碼。這是很清楚的:
/**
* 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;
}
如果您想通過10次命中每5分鐘,以限制某些活動,比decayMinutes
必須爲5
我瞭解decayMinutes
作爲保留時間。對於實際情況,如果您想嘗試使用錯誤的密碼進行登錄,但如果他嘗試了11次,則用戶將被阻止達到decayMinutes
中指定的分鐘數。如果您指定10分鐘作爲您的decayMinutes
,用戶被阻止10分鐘
從具有閱讀源代碼,這是我的理解了。 – fubar
這是錯誤的答案。 'decayMinutes'(在Laravel 5.5)不是一個阻止時間。 –
我猜登錄塊時間就是一個例子,它的工作方式大部分與節流相同。只需將「登錄嘗試」替換爲「請求的唯一網址」即可。如果您沒有爲$ decayMinutes分鐘發出任何頁面或API請求,那麼油門計數器將重置。 –