PHPackages                             trukes/php-rate-limiter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. trukes/php-rate-limiter

ActiveLibrary[HTTP &amp; Networking](/categories/http)

trukes/php-rate-limiter
=======================

A lightweight, flexible rate-limiting library for PHP. Manage access limits by user, IP, or custom keys with support for sliding and fixed windows. Compatible with Redis, MySQL, and file-based storage. Ideal for controlling API usage and preventing abuse.

v1.0.1(1y ago)2141MITPHPPHP ^8.0CI passing

Since Jan 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Trukes/php-rate-limiter)[ Packagist](https://packagist.org/packages/trukes/php-rate-limiter)[ Docs](https://github.com/trukes/php-rate-limiter)[ RSS](/packages/trukes-php-rate-limiter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Php Rate Limiter
================

[](#php-rate-limiter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/35a760fce03858af6821b15ac51ba2e46a0b45fb51e2a4af46af7503d384b183/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7472756b65732f7068702d726174652d6c696d697465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/trukes/php-rate-limiter)[![Total Downloads](https://camo.githubusercontent.com/bada9cf47b154248e9b7abee2a57776a3466a3c2aabb8e4507a05505766cbbd6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7472756b65732f7068702d726174652d6c696d697465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/trukes/php-rate-limiter)[![GitHub Actions](https://github.com/trukes/php-rate-limiter/actions/workflows/main.yml/badge.svg)](https://github.com/trukes/php-rate-limiter/actions/workflows/main.yml/badge.svg)

PhpRateLimiter is a simple and flexible rate-limiting library for PHP. It allows you to manage access limits based on custom keys (such as users, IPs, etc.) and can be easily integrated with any injectable storage backend (e.g., Redis, MySQL, etc.). It supports both fixed and sliding time windows. Ideal for controlling API usage and preventing abuse.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require trukes/php-rate-limiter
```

Usage
-----

[](#usage)

```
use Trukes\PhpRateLimiter\PhpRateLimiter;
use Psr\SimpleCache\CacheInterface;
use Trukes\PhpRateLimiter\Support\Config;
use Trukes\PhpRateLimiter\Exception\LimitExceededException;

// Example with a PSR-16 compatible cache implementation
$cache = // Your cache implementation (e.g., Redis, file-based cache, etc.)
$config = new Config();

// Instantiate the rate limiter
$rateLimiter = new PhpRateLimiter($cache, $config);

$key = 'user_123'; // Custom key (e.g., user ID, IP, etc.)

try {
    $rateLimiter->hit($key); // Increment the hit count
} catch (LimitExceededException $e) {
    echo 'Limit exceeded: ' . $e->getMessage();
}

// Reset the counter for a key
$rateLimiter->reset($key);
```

### Configuration

[](#configuration)

You are able to provider configurations to fit your needs:

```
new Config(
    prefix: 'your-prefix',
    maxRequestsByTimeframe: 10,
    timeframeInSeconds: 1
);
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Pedro Carmo](https://github.com/trukes)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

PHP Package Boilerplate
-----------------------

[](#php-package-boilerplate)

This package was generated using the [PHP Package Boilerplate](https://laravelpackageboilerplate.com) by [Beyond Code](http://beyondco.de/).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance44

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

464d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4dc33a2d40d69727b4af27491f6d1d0894bb98d618de1545e3ed5d7520ef8b18?d=identicon)[Trukes](/maintainers/Trukes)

---

Top Contributors

[![Trukes](https://avatars.githubusercontent.com/u/6023213?v=4)](https://github.com/Trukes "Trukes (4 commits)")

---

Tags

trukesphp-rate-limiter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/trukes-php-rate-limiter/health.svg)

```
[![Health](https://phpackages.com/badges/trukes-php-rate-limiter/health.svg)](https://phpackages.com/packages/trukes-php-rate-limiter)
```

###  Alternatives

[league/route

Fast routing and dispatch component including PSR-15 middleware, built on top of FastRoute.

6633.1M116](/packages/league-route)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)[mimmi20/browser-detector

Library to detect Browsers and Devices

48153.5k3](/packages/mimmi20-browser-detector)[sunrise/http-router

A powerful solution as the foundation of your project.

16249.8k10](/packages/sunrise-http-router)[eljam/guzzle-jwt-middleware

A jwt authentication middleware for guzzle 6

28722.5k3](/packages/eljam-guzzle-jwt-middleware)[brightfish/caching-guzzle

Cache HTTP responses through Guzzle middleware

1031.5k](/packages/brightfish-caching-guzzle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
