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)2157MITPHPPHP ^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 2d 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

28

—

LowBetter than 52% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity13

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

521d 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

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[illuminate/contracts

The Illuminate Contracts package.

706130.3M13.4k](/packages/illuminate-contracts)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.1M159](/packages/algolia-algoliasearch-client-php)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[laudis/neo4j-php-client

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

185702.8k44](/packages/laudis-neo4j-php-client)[hyperf/hyperf

A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.

6.9k3.3k2](/packages/hyperf-hyperf)

PHPackages © 2026

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