PHPackages                             marko/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. [Framework](/categories/framework)
4. /
5. marko/ratelimiter

ActiveMarko-module[Framework](/categories/framework)

marko/ratelimiter
=================

Rate limiting for Marko Framework

0.8.4(1mo ago)02MITPHPPHP ^8.5

Since May 29Pushed 1mo agoCompare

[ Source](https://github.com/marko-php/marko-ratelimiter)[ Packagist](https://packagist.org/packages/marko/ratelimiter)[ RSS](/packages/marko-ratelimiter/feed)WikiDiscussions develop Synced 1w ago

READMEChangelogDependencies (12)Versions (7)Used By (0)

marko/ratelimiter
=================

[](#markoratelimiter)

Rate limiting for Marko — throttle requests by key with configurable windows and cache-backed hit counts.

Overview
--------

[](#overview)

`marko/ratelimiter` provides a simple, cache-backed rate limiter that integrates with Marko's routing layer via middleware. Define limits by key (IP, user ID, API token, etc.) with configurable max attempts and decay windows. The `RateLimiter` class is the core service; `RateLimitMiddleware` applies limits to routes automatically.

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

[](#installation)

```
composer require marko/ratelimiter
```

Usage
-----

[](#usage)

Apply the middleware to a route group:

```
use Marko\RateLimiter\Middleware\RateLimitMiddleware;

$router->group(['middleware' => RateLimitMiddleware::class], function ($router): void {
    $router->get('/api/search', SearchController::class);
});
```

Use the service directly for custom logic:

```
use Marko\RateLimiter\RateLimiter;

$result = $rateLimiter->attempt(
    key: 'api:' . $request->ip(),
    maxAttempts: 60,
    decaySeconds: 60,
);

if ($result->exceeded()) {
    throw new TooManyRequestsException($result->retryAfter);
}
```

API Reference
-------------

[](#api-reference)

- `RateLimiter::attempt(string $key, int $maxAttempts, int $decaySeconds)` — Record a hit and return a `RateLimitResult`
- `RateLimiter::clear(string $key)` — Reset the counter for a key
- `RateLimitResult::exceeded()` — Whether the limit has been breached
- `RateLimitResult::$remaining` — Remaining attempts
- `RateLimitResult::$retryAfter` — Seconds until the window resets

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

[](#documentation)

Full configuration and middleware usage: [marko/ratelimiter](https://marko.build/docs/packages/ratelimiter/)

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance93

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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 ~4 days

Total

5

Last Release

42d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/437029?v=4)[Mark Shust](/maintainers/markshust)[@markshust](https://github.com/markshust)

---

Top Contributors

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

###  Code Quality

TestsPest

### Embed Badge

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

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

PHPackages © 2026

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