PHPackages                             evoluted/php-ratelimiter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. evoluted/php-ratelimiter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

evoluted/php-ratelimiter
========================

A framework agnostic rate limiter for PHP

1.3.1(9y ago)441.5k↓50%1MITPHPPHP &gt;=5.5

Since Sep 7Pushed 9y ago6 watchersCompare

[ Source](https://github.com/EvolutedNewMedia/php-ratelimiter)[ Packagist](https://packagist.org/packages/evoluted/php-ratelimiter)[ RSS](/packages/evoluted-php-ratelimiter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (11)Used By (0)

PHP Ratelimiter
===============

[](#php-ratelimiter)

A framework independent, flexible and highly extensible rate limiter for PHP.

[![SensioLabsInsight](https://camo.githubusercontent.com/1aa295c3e5d75765796640524ace2c6baf8ca8432ec0f094faa9fc22edafb058/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f35316265303133372d313135382d343033612d396663372d6162383633663263306361392f6d696e692e706e67)](https://insight.sensiolabs.com/projects/51be0137-1158-403a-9fc7-ab863f2c0ca9)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5aa6231958d0c08a97571dd523a86e22783c3351715939a2cd2c332e2608c42a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73756e7370696b65732f7068702d726174656c696d697465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sunspikes/php-ratelimiter/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/57b4a62ce9f5bc4c2ed394885cd360790aea0cce700bf3e5801d23b216dca558/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73756e7370696b65732f7068702d726174656c696d697465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sunspikes/php-ratelimiter/?branch=master)[![Code Climate](https://camo.githubusercontent.com/21327c59b4a9f1cb4d293ead449e439f228d4e9e27e0bac890da19dbdabd0ed2/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73756e7370696b65732f7068702d726174656c696d697465722f6261646765732f6770612e737667)](https://codeclimate.com/github/sunspikes/php-ratelimiter)[![Build Status](https://camo.githubusercontent.com/54c641765fb02ed205f53536428dbaf3c94ff991d2062b45a8f39a2c60786312/68747470733a2f2f7472617669732d63692e6f72672f73756e7370696b65732f7068702d726174656c696d697465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sunspikes/php-ratelimiter)[![Latest Stable Version](https://camo.githubusercontent.com/58942e00f189dd3036973786d3b2b9c49c14422a2cf3fdffe2e5afb2c3a0e405/68747470733a2f2f706f7365722e707567782e6f72672f73756e7370696b65732f7068702d726174656c696d697465722f762f737461626c65)](https://packagist.org/packages/sunspikes/php-ratelimiter)[![License](https://camo.githubusercontent.com/be7e824ffd0739df8a98185e0c8d2a9ee0d5028acb13c5b836a4e3d9630af80b/68747470733a2f2f706f7365722e707567782e6f72672f73756e7370696b65732f7068702d726174656c696d697465722f6c6963656e7365)](https://packagist.org/packages/sunspikes/php-ratelimiter)

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

[](#installation)

### With Composer

[](#with-composer)

It is best installed it through [packagist](http://packagist.org/packages/sunspikes/php-ratelimiter)by including `sunspikes/php-ratelimiter` in your project composer.json require:

```
    "require": {
        "sunspikes/php-ratelimiter":  "dev-master"
    }
```

### Without Composer

[](#without-composer)

You can also download it from \[Github\] (), but no autoloader is provided so you'll need to register it with your own PSR-4 compatible autoloader.

Usage
-----

[](#usage)

### Overview

[](#overview)

```
// 1. Make a rate limiter with limit 3 attempts in 10 minutes
$cacheAdapter = new DesarrollaCacheAdapter((new DesarrollaCacheFactory())->make());
$ratelimiter = new RateLimiter(new ThrottlerFactory(), new HydratorFactory(), $cacheAdapter, 3, 600);

// 2. Get a throttler for path /login
$loginThrottler = $ratelimiter->get('/login');

// 3. Register a hit
$loginThrottler->hit()

// 4. Check if it reached the limit
if ($loginThrottler->check()) {
    // access permitted
} else {
    // access denied
}

// Or combine the steps 3 & 4
if ($loginThrottler->access()) {
    // access permitted
} else {
    // access denied
}

// To get the number of hits
print $loginThrottler->count(); // or count($throttler)
```

### Configuration

[](#configuration)

By default PHP Ratelimiter uses the [desarolla2 cache adapter](https://github.com/desarrolla2/Cache), the sample configuration provided in `config/config.php`

You can configure the drivers in `config.php`, for example to use memcache change the driver to `'memcache'`

```
return [
    'default_ttl' => 3600,
    'driver'      => 'memcache',
    'memcache' => [
        //....
    ],
];
```

### Extending

[](#extending)

The PHP Ratelimiter is highly extensible, you can have custom adapters by implementing `Sunspikes\Ratelimit\Cache\Adapter\CacheAdapterInterface`

For example to use Doctrine cache adapter

```
class DoctrineCacheAdapter implements CacheAdapterInterface
{
    public function __construct($cache)
    {
        $this->cache = $cache;
    }

    // Implement the methods
}

// Build adapter using APC cache driver
$adapter = new DoctrineCacheAdapter(new \Doctrine\Common\Cache\ApcCache());
```

Also you can have custom hydrators by implementing `Sunspikes\Ratelimit\Throttle\Hydrator\DataHydratorInterface`

For example to use a Symfony Request object instead of custom URL for ratelimiting

```
class RequestHydrator implements DataHydratorInterface
{
    public function hydrate($data, $limit, $ttl)
    {
        // Make the key string
        $key = $data->getClientIp() . $data->getPathInfo();

        return new Data($key, $limit, $ttl);
    }
}

// Hydrate the request to Data object
$hydrator = new RequestHydrator();
```

Then decorate or extend the HydratorFactory to recognize your data

```
use Hydrator\FactoryInterface;

class MyHydratorFactory implements FactoryInterface
{
    private $defaultFactory;

    public function __construct(FactoryInterface $defaultFactory)
    {
        $this->defaultFactory = $defaultFactory;
    }

    public function make($data)
    {
        if ($data instanceof Request) {
            return new RequestHydrator();
        }

        return $this->defaultFactory->make($data);
    }
}
```

Author
------

[](#author)

Krishnaprasad MG \[@sunspikes\]

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

[](#contributing)

Please feel free to send pull requests.

License
-------

[](#license)

This is an open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 76.8% 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 ~70 days

Recently: every ~75 days

Total

6

Last Release

3554d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/249d852b103b90c391be045688903bad7da259b49f235695e629c70ff9706b3b?d=identicon)[evoluted](/maintainers/evoluted)

---

Top Contributors

[![sunspikes](https://avatars.githubusercontent.com/u/75611?v=4)](https://github.com/sunspikes "sunspikes (53 commits)")[![Feijs](https://avatars.githubusercontent.com/u/12059414?v=4)](https://github.com/Feijs "Feijs (11 commits)")[![digibeuk](https://avatars.githubusercontent.com/u/5148394?v=4)](https://github.com/digibeuk "digibeuk (2 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")[![biggins](https://avatars.githubusercontent.com/u/1213577?v=4)](https://github.com/biggins "biggins (1 commits)")

---

Tags

rate limitthrottlethrottlingratelimitKrishnaprasad MGsunspikesphp-ratelimiter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/evoluted-php-ratelimiter/health.svg)

```
[![Health](https://phpackages.com/badges/evoluted-php-ratelimiter/health.svg)](https://phpackages.com/packages/evoluted-php-ratelimiter)
```

###  Alternatives

[sunspikes/php-ratelimiter

A framework agnostic rate limiter for PHP

76674.1k1](/packages/sunspikes-php-ratelimiter)[davedevelopment/stiphle

Simple rate limiting/throttling for php

2567.7M9](/packages/davedevelopment-stiphle)[bandwidth-throttle/token-bucket

Implementation of the Token Bucket algorithm.

5121.9M10](/packages/bandwidth-throttle-token-bucket)[graham-campbell/throttle

Throttle Is A Rate Limiter For Laravel

7102.3M11](/packages/graham-campbell-throttle)[hamburgscleanest/guzzle-advanced-throttle

A Guzzle middleware that can throttle requests according to (multiple) defined rules. It is also possible to define a caching strategy, e.g. get response from cache when rate limit is exceeded or always get cached value to spare your rate limits.

13033.4k1](/packages/hamburgscleanest-guzzle-advanced-throttle)[bandwidth-throttle/bandwidth-throttle

Bandwidth throttle at application layer

87139.3k](/packages/bandwidth-throttle-bandwidth-throttle)

PHPackages © 2026

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