Download the PHP package aporat/laravel-rate-limiter without Composer

On this page you can find all versions of the php package aporat/laravel-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 laravel-rate-limiter

Laravel Rate Limiter

Latest Stable Version Downloads Codecov Laravel Version GitHub Actions Workflow Status License

A flexible rate limiting middleware for Laravel applications, designed to throttle requests and actions using Redis.

Features

Requirements

Installation

Install the package via Composer:

RateLimiterServiceProvider is registered automatically via Laravel's package discovery. If auto-discovery is disabled, add it to bootstrap/providers.php:

The package deliberately does not register a RateLimiter class alias, because that name is taken by Laravel's own Illuminate\Support\Facades\RateLimiter. Import this package's facade by its full name instead:

Publish the configuration file:

Configuration

Edit config/rate-limiter.php:

Anything set explicitly under redis overrides the named connection it inherits from. prefix is applied by the package rather than through Redis::OPT_PREFIX, so the keys the package scans and deletes are the same names it writes.

Config is read live from the container on each call, so a runtime Config::set() is picked up by the long-lived singleton.

Usage

Middleware

The provider registers the rate.limiter alias. Apply it to a route group:

Or register it globally in bootstrap/app.php:

Each configured window (hourly, minute, second) gets its own counter keyed on the client IP; a window set to 0 is skipped. Addresses matching whitelisted_ips bypass the middleware entirely.

Put the middleware after your trusted-proxy middleware, so getClientIp() returns the real client rather than the load balancer.

Manual Rate Limiting

create() resets the tag, window and attached response, so the singleton is safe to reuse. limit() throws RateLimitException once the count passes the limit; record() increments and returns the count without throwing, which is what you want for duplicate-request detection:

The increment and its expiry are applied in a single Lua script, so a counter can never be left without a window if the process dies mid-call, and a key that has somehow lost its TTL gets one back on the next write.

IP Blocking

IPv6 addresses are grouped by their /64 prefix for both counting and blocking, so a single client cannot rotate through a subnet it already controls.

Rate Limit Headers

Exception handling

RateLimitException implements HttpExceptionInterface, so Laravel renders it as a 429 with a Retry-After header out of the box. Two deliberate omissions:

With log_errors set to false, report() returns false so Laravel continues on to your registered report callbacks:

Request bodies and headers written to the log are redacted for the usual credential keys (authorization, cookie, password, x-auth-signature, ...).

Testing

The suite talks to a real Redis on 127.0.0.1:6379 (database 15), overridable with REDIS_HOST and REDIS_PORT:

Static analysis and code style:

Contributing

Contributions are welcome! Please:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/new-feature).
  3. Commit your changes (git commit -m "Add new feature").
  4. Push to the branch (git push origin feature/new-feature).
  5. Open a pull request.

Report issues at GitHub Issues.

License

This package is licensed under the License File for details.

Support


All versions of laravel-rate-limiter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^12.0 || ^13.0
illuminate/http Version ^12.0 || ^13.0
illuminate/log Version ^12.0 || ^13.0
illuminate/redis Version ^12.0 || ^13.0
illuminate/routing Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
symfony/http-foundation Version ^7.2 || ^8.0
symfony/http-kernel Version ^7.2 || ^8.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 aporat/laravel-rate-limiter contains the following files

Loading the files please wait ...