PHPackages                             syeedalireza/api-rate-limiter-bundle - 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. [Caching](/categories/caching)
4. /
5. syeedalireza/api-rate-limiter-bundle

ActiveSymfony-bundle[Caching](/categories/caching)

syeedalireza/api-rate-limiter-bundle
====================================

Enterprise-grade API rate limiting for Symfony. Supports multiple algorithms (Token Bucket, Sliding Window, Fixed Window), distributed limiting with Redis, and comprehensive analytics. Perfect for production APIs requiring precise request throttling.

v1.0.0(3mo ago)00MITPHPPHP ^8.2CI failing

Since Jan 31Pushed 3mo agoCompare

[ Source](https://github.com/syeedalireza/api-rate-limiter-bundle)[ Packagist](https://packagist.org/packages/syeedalireza/api-rate-limiter-bundle)[ RSS](/packages/syeedalireza-api-rate-limiter-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (16)Versions (2)Used By (0)

API Rate Limiter Bundle
=======================

[](#api-rate-limiter-bundle)

[![Latest Stable Version](https://camo.githubusercontent.com/c73513dde76f96359c7507dde75c8611aa3c45acba253ec206b5bbc330c477e8/68747470733a2f2f706f7365722e707567782e6f72672f7379656564616c6972657a612f6170692d726174652d6c696d697465722d62756e646c652f762f737461626c65)](https://packagist.org/packages/syeedalireza/api-rate-limiter-bundle)[![License](https://camo.githubusercontent.com/58a1e2fb91343cf6d03a21d7bc251ef3a1692e284374706b9b70edcbc0879ca6/68747470733a2f2f706f7365722e707567782e6f72672f7379656564616c6972657a612f6170692d726174652d6c696d697465722d62756e646c652f6c6963656e7365)](https://packagist.org/packages/syeedalireza/api-rate-limiter-bundle)[![PHP Version](https://camo.githubusercontent.com/c9f64f714c636ba27a3bba6dfd52f98426832db1262747efa54b212d16943651/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d626c7565)](https://www.php.net/)

Enterprise-grade **API Rate Limiting** for Symfony applications with multiple algorithms, distributed support via Redis, and comprehensive analytics.

🚀 Features
----------

[](#-features)

- **Multiple Algorithms**: Token Bucket, Sliding Window, Fixed Window, Leaky Bucket
- **Distributed Rate Limiting**: Redis-based for microservices
- **Flexible Limits**: Per IP, User, API Key, or Endpoint
- **RFC Compliance**: RateLimit-\* HTTP headers
- **Analytics**: Real-time metrics and monitoring
- **PHP 8 Attributes**: Modern configuration style
- **Production Ready**: Battle-tested, optimized Lua scripts

📦 Installation
--------------

[](#-installation)

```
composer require syeedalireza/api-rate-limiter-bundle
```

🎯 Quick Start
-------------

[](#-quick-start)

### 1. Configure

[](#1-configure)

```
# config/packages/rate_limiter.yaml
rate_limiter:
    default_algorithm: token_bucket
    redis:
        client: 'redis://localhost:6379'
    limits:
        api:
            limit: 100
            window: 3600  # 1 hour
```

### 2. Use Attributes

[](#2-use-attributes)

```
use Syeedalireza\RateLimiterBundle\Attribute\RateLimit;

#[RateLimit(limit: 100, window: 3600)]
class ApiController extends AbstractController
{
    #[Route('/api/users')]
    #[RateLimit(limit: 10, window: 60, key: 'ip')]
    public function getUsers(): JsonResponse
    {
        // Max 10 requests per minute per IP
    }
}
```

### 3. Check Limits Programmatically

[](#3-check-limits-programmatically)

```
use Syeedalireza\RateLimiterBundle\Service\RateLimiter;

public function __construct(
    private RateLimiter $rateLimiter
) {}

public function someAction(): Response
{
    $status = $this->rateLimiter->check('user:123', limit: 100, window: 3600);

    if (!$status->isAllowed()) {
        throw new TooManyRequestsHttpException(
            $status->getRetryAfter(),
            'Rate limit exceeded'
        );
    }
}
```

📊 Algorithms
------------

[](#-algorithms)

### Token Bucket

[](#token-bucket)

Best for burst tolerance with steady rate.

```
#[RateLimit(algorithm: 'token_bucket', limit: 100, window: 60)]
```

### Sliding Window

[](#sliding-window)

Most accurate, prevents boundary issues.

```
#[RateLimit(algorithm: 'sliding_window', limit: 100, window: 60)]
```

### Fixed Window

[](#fixed-window)

Simple, efficient, but has boundary spikes.

```
#[RateLimit(algorithm: 'fixed_window', limit: 100, window: 60)]
```

🔧 Advanced Usage
----------------

[](#-advanced-usage)

### Custom Cost per Endpoint

[](#custom-cost-per-endpoint)

```
#[RateLimit(limit: 1000, window: 3600, cost: 10)]
public function heavyOperation(): Response
{
    // This request costs 10 tokens
}
```

### Whitelist/Blacklist

[](#whitelistblacklist)

```
rate_limiter:
    whitelist:
        - '192.168.1.100'
        - '10.0.0.0/8'
    blacklist:
        - '185.220.101.0/24'  # Tor exit nodes
```

### Multiple Limits

[](#multiple-limits)

```
#[RateLimit(limit: 10, window: 1)]     // 10 per second
#[RateLimit(limit: 100, window: 60)]   // 100 per minute
#[RateLimit(limit: 1000, window: 3600)] // 1000 per hour
public function api(): Response {}
```

📈 Monitoring
------------

[](#-monitoring)

```
$metrics = $this->rateLimiter->getMetrics('user:123');

echo $metrics->getRequestCount();
echo $metrics->getRemainingTokens();
echo $metrics->getResetTime();
```

🐳 Docker Support
----------------

[](#-docker-support)

Included Redis setup for development:

```
docker-compose up -d
```

📚 Documentation
---------------

[](#-documentation)

- [Installation Guide](docs/installation.md)
- [Configuration Reference](docs/configuration.md)
- [Algorithms Comparison](docs/algorithms.md)
- [Performance Benchmarks](docs/benchmarks.md)

🧪 Testing
---------

[](#-testing)

```
composer test           # Run tests
composer benchmark      # Run performance benchmarks
composer quality        # All quality checks
```

🤝 Contributing
--------------

[](#-contributing)

See [CONTRIBUTING.md](CONTRIBUTING.md)

📄 License
---------

[](#-license)

MIT License - see [LICENSE.md](LICENSE.md)

👨‍💻 Author
----------

[](#‍-author)

**Alireza Aminzadeh**

- Email:
- GitHub: [@syeedalireza](https://github.com/syeedalireza)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance81

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

99d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/05de5f56c8b265c6720d5a4593d499a06c5a32b7ed2b7c36e0ac73778f09a381?d=identicon)[syeedalireza](/maintainers/syeedalireza)

---

Tags

middlewareapisymfonyredisthrottlingrate limitingproductiondistributedtoken bucketsliding-window

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/syeedalireza-api-rate-limiter-bundle/health.svg)

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

###  Alternatives

[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M232](/packages/nelmio-api-doc-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[scheb/2fa

Two-factor authentication for Symfony applications (please use scheb/2fa-bundle to install)

578630.7k1](/packages/scheb-2fa)[scheb/2fa-bundle

A generic interface to implement two-factor authentication in Symfony applications

6914.0M61](/packages/scheb-2fa-bundle)[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

841.4M16](/packages/tedivm-stash-bundle)[mmoreram/rsqueue-bundle

Redis Symfony2 Queue Bundle, a simple and soft redis based message queue for symfony2

5360.7k1](/packages/mmoreram-rsqueue-bundle)

PHPackages © 2026

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