cschalenborgh/laravel-rate-limiter

Rate limiter for Laravel

1.0.3 2020-04-17 15:44 UTC

This package is auto-updated.

Last update: 2024-12-18 02:44:50 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-limiter

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 RateLimiter('action_name', 5, 60); // max 5 times in 60 seconds

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