PHPackages                             phparmory/rate - 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. phparmory/rate

ActivePackage

phparmory/rate
==============

Rate limiter with different stategies

0.2.1(9y ago)021MITPHP

Since May 22Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (4)Used By (0)

Rate
====

[](#rate)

A simple but extentable rate limiting package.

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

[](#installation)

Install using composer.

```
composer require phparmory/rate

```

Rate requires PHP7 to run.

Documentation
-------------

[](#documentation)

### Actors

[](#actors)

Actors are the entities that can be rate limited. They are identified by an IP address:

```
use Armory\Rate\{
    ActorFactory
};

$actorFactory = new ActorFactory();

$actor = $actorFactory->create('127.0.0.1');
```

### Events

[](#events)

Events are entities that can be rate limited. Event are identified by name, can have a cost (discussed later) and is triggered by an actor.

```
use Armory\Rate\{
    EventFactory
};

$eventFactory = new EventFactory();

$event = $eventFactory->create('request.user.api', 1, $actor); // Cost of 1
```

### Rate Limits

[](#rate-limits)

Rate limits are entities that contain information about the imposed limits. Rate limits can have a number of attempts, a timeframe and a penalty (discussed later).

```
use Armory\Rate\{
    RateLimitFactory
};

$rateLimitFactory = new RateLimitFactory();

$rateLimit = $rateLimitFactory->create(100, 60, 10); // 100 requests per minute (60 seconds) with a penalty of 10 seconds for hitting the rate limit
```

### Event Repositories

[](#event-repositories)

Events can be persisted to a storage medium so that rate limits can be imposed across requests. Rate comes with a FakeRepository (in-memory) to get you started.

```
use Armory\Rate\{
    EventRepositoryFactory
};

$eventRepositoryFactory = new EventRepositoryFactory();

$repository = $eventRepositoryFactory->create(); // Defaults to FakeRepository
```

### Rate Limiters

[](#rate-limiters)

Rate limiters are services that define a strategy for rate limiting. Rate comes with two main rate limiting strategies:

- Basic rate limiting e.g. 100 requests every hour
- Dynamic rate limiting i.e. leaky bucket

```
use Armory\Rate\{
    RateLimiterFactory
};

$rateLimiterFactory = new RateLimiterFactory();

$rateLimiter = $rateLimiterFactory->dynamic($event, $limit, $repository);

$rateLimiter->run();
```

If a rate limited is exceeded it will throw a `Armory\Rate\Exceptions\RateLimitExceededException`.

### Costs

[](#costs)

Costs allow for a cost/balance implementation whereby imposing a limit of 100 on the rate limiter gives the actor a balance of 100 credits. Each event 'costs' a number of credits which subtract from the total balance. For example:

```
use Armory\Rate\{
    EventFactory;
};

$eventFactory = new EventFactory;

$userApi = $eventFactory->create('user.api', 1, 0); // 1 credit
$postsApi = $eventFactory->create('posts.api', 2, 0); // 2 credits
```

### Penalties

[](#penalties)

A third parameter to creating an event allows you to specify a penalty for hitting the rate limit. If a rate limit is hit, the penalty time prevents the rate limit from passing even if the actor would usually have credits.

```
use Armory\Rate\{
    EventFactory
};

$eventFactory = new EventFactory;

$userApi = $eventFactory->create('user.api', 1, 20); // Hitting the rate limit puts the actor in timeout for 20 seconds
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity55

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

Every ~1 days

Total

3

Last Release

3638d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6439906fd9efc2ef34e707b824d3e944c8589a9f1a82ace6997146abb7b8415d?d=identicon)[rphcrosby](/maintainers/rphcrosby)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phparmory-rate/health.svg)

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

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)[sassnowski/venture

A package to manage complex workflows built on top of Laravel's queue.

825254.5k1](/packages/sassnowski-venture)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)[bol-com/retailer-api

Package to talk to the bol.com v8 API.

1145.9k](/packages/bol-com-retailer-api)

PHPackages © 2026

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