cschalenborgh/laravel-rate-limiter

Rate limiter for Laravel

1.0.2 2019-10-03 08:07 UTC

README

Latest Version on Packagist Build Status Code Coverage (GitHub) StyleCI Total Downloads License: MIT

Description

You can use this package to easily rate limiter specific logic in your Laravel application, from Guzzle requests, to more specific application logic. This package is based on https://github.com/touhonoob/RateLimit.

Installation

You can install the package via composer:

composer require cschalenborgh/laravel-rate-limieter

The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:

'providers' => [
    // ...
    Cschalenborgh\RateLimiter\RateLimiterServiceProvider::class,
];

Usage

use Cschalenborgh\RateLimiter\RateLimiter;

$rate_limiter = new RateLimit('action_name', 5, 60); // max 5 times in 60 seconds

if ($rate_limiter->check($lock_identifier)) {
    // perform some action
} else {
    // oops.. limit reached
}