Download the PHP package sanmai/rate-limiter without Composer

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

Rate Limiter 🚦⏱️

Latest Stable Version License

Cache-based API rate limiting for PHP applications

A lightweight, efficient PHP library for controlling request rates and preventing API abuse.

Table of Contents

Installation

Overview

Need to prevent API abuse, protect your services from excessive traffic, or implement fair usage policies? This library provides a simple solution for rate limiting with the sliding window approach.

Real-world example: Imagine you need to limit API requests to 100 per minute and 1000 per hour per client. This library lets you create a rate limiter with a 1-minute window and 1-hour observation period, then check if a client exceeds either of these limits.

Features

Two-level limiting - Window-based and period-based limits
Lazy evaluation - Calculates limits only when needed
Simple API - Easy-to-use interface for rate limiting
Detailed feedback - Clear information about rate limit status
Compatible with PHP 8.1+ - Works with modern PHP versions
PSR-compatible - Easily integrates with PSR-15 middleware

How it works (the simple version)

This rate limiter provides two types of limits:

  1. Window limits - Controls request rates in the most recent time window (e.g., 100 requests per minute)
  2. Period limits - Controls total requests over a longer observation period (e.g., 1000 requests per hour)

The rate limiter itself tracks requests, while the limits are set when checking if they've been exceeded.

Quick Start

Setting up a rate limiter

Tracking requests

Checking rate limits

Getting more information

Advanced Usage

Using multiple rate limiters for different constraints

You can create different rate limiters for different types of constraints:

Implementing in middleware

Here's how you might implement rate limiting in a PSR-15 middleware:

Error Handling

Here are some common scenarios and how to handle them:

Cache Adapters

This library uses the cache adapters provided by the sanmai/sliding-window-counter package. For information about available adapters and how to create your own, please refer to the sliding window counter documentation.

Technical Details

This rate limiter is built on top of the sliding window counter library, which provides an efficient implementation of the sliding window algorithm.

How the Sliding Window Algorithm Works

Unlike fixed window rate limiting (which can allow bursts of traffic at window boundaries), the sliding window approach provides smoother rate limiting by considering a continuously moving time window.

The key components of this rate limiter are:

The library uses deferred evaluation through the sanmai/later package to ensure efficient processing, only calculating limits when they're actually needed.

Requirements

For more detailed technical information about how the sliding window algorithm works, please refer to the sliding window counter documentation.

Contributing

Contributions are welcome! Here are some ways you can contribute:

Please ensure your code follows the existing style and includes appropriate tests.

License

This library is licensed under the GNU General Public License v2.0. See the LICENSE file for details.


All versions of rate-limiter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
sanmai/later Version ^0.1.5
sanmai/pipeline Version ^6.11
sanmai/sliding-window-counter Version ^0.1
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 sanmai/rate-limiter contains the following files

Loading the files please wait ....