Download the PHP package bvtterfly/sliding-window-rate-limiter without Composer

On this page you can find all versions of the php package bvtterfly/sliding-window-rate-limiter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sliding-window-rate-limiter

🚨 THIS PACKAGE HAS BEEN ABANDONED 🚨

I no longer use Laravel and cannot justify the time needed to maintain this package. That's why I have chosen to abandon it. Feel free to fork my code and maintain your own copy.

Laravel Sliding Window Rate Limiter

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides an easy way to limit any action during a specified time window. You may be familiar with Laravel's Rate Limiter, It has a similar API, but it uses the Sliding Window algorithm and requires Redis.

Installation

You can install the package via composer:

You can publish the config file with:

This is the contents of the published config file:

The package relies on Redis and requires a Redis connection, and you choose which Redis connection to use.

Usage

The Bvtterfly\SlidingWindowRateLimiter\Facades\SlidingWindowRateLimiter facade may be used to interact with the rate limiter.

The simplest method offered by the rate limiter is the attempt method, which rate limits an action for a given number of seconds. The attempt method returns a result object that specifies if an attempt was successful and how many attempts remain. If the attempt is unsuccessful, you can get the number of seconds until the action is available again.

You can call the following methods on the SlidingWindowRateLimiter:

tooManyAttempts

attempts

resetAttempts

remaining

clear

availableIn

retriesLeft

Route Rate Limiting

This package comes with a throttle middleware for Route Rate Limiting. It can replace the default Laravel's throttle middleware to use this package rate limiter. The only difference is it tries to get a named rate limiter from the SlidingWindowRateLimiter or, as a fallback, it will take them from Laravel RateLimiter.

You may wish to change the mapping of throttle middleware in your application's HTTP kernel(App\Http\Kernel) to use \Bvtterfly\SlidingWindowRateLimiter\Http\Middleware\ThrottleRequests class.

Rate Limiters must be configured for route rate-limiting to work. Laravel Rate Limiter comes with a RateLimiting class(Illuminate\Cache\RateLimiting\Limit) that works in a minutes-based system. But This package is designed to allow rate limit actions in a seconds-based system, so it comes with its rate limiters classes and lets you configure rate limiters for less than a minute. Still, for ease of usage of this package, It supports default Laravel's Rate Limiters.

Defining Rate Limiters

SlidingWindowRateLimiter rate limiters are heavily based on Laravel's rate limiters. It only differs in the fact that it is seconds-based. So, before getting started, be sure to read about them on Laravel docs.

Limit configurations are instances of the Bvtterfly\SlidingWindowRateLimiter\RateLimiting\Limit class, and It contains helpful "builder" methods to define your rate limits quickly. The rate limiter name may be any string you wish.

For limiting to 500 requests in 45 seconds:

If the incoming request exceeds the specified rate limit, a response with a 429 HTTP status code will automatically be returned by Laravel. If you would like to define your response that a rate limit should return, you may use the response method:

You can have multiple rate limits. This configuration will limit only 100 requests per 30 seconds and 1000 requests per day:

Incoming HTTP request instances are passed to rate limiter callbacks, and the rate limit may be calculated dynamically depending on the user or request:

There may be times when you wish to segment rate limits by some arbitrary value. For example, you may want to allow users to access a given route with 100 requests per minute per authenticated user ID and 10 requests per minute per IP address for guests. Using the by a method, you can create your rate limit as follows:

Attaching Rate Limiters To Routes

Rate limiters can be attached to routes or route groups using the throttle middleware. The throttle middleware accepts the name of the rate limiter you wish to assign to the route:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of sliding-window-rate-limiter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
spatie/laravel-package-tools Version ^1.9.2
illuminate/contracts Version ^9.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bvtterfly/sliding-window-rate-limiter contains the following files

Loading the files please wait ....