Search by

naf / rate-limit

floknapp

Atomic PDO fixed-window rate limits for NAF hosts.

Package info

github.com/nafphp/rate-limit

Type:naf-plugin

pkg:composer/naf/rate-limit

Statistics

Installs: 21

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-09-19 10:44 UTC

This package is auto-updated.

Last update: 2026-09-21 21:23:55 UTC


README

Count attempts, and refuse the ones over the line.

Atomic fixed-window counters in your database, registered as a rateLimit guard on NAF's existing Naf\guard() registry. Installing it intercepts nothing: the host chooses the keys, the limits and what a refusal looks like.

$decision = guard()->rateLimit('export:account:' . $accountId, 10, 60);

if (!$decision['allowed']) {
    return json(['error' => 'Too many requests'], 429)
        ->withHeader('Retry-After', (string) $decision['retry_after']);
}

🧩 Part of the official NAF plugin collection. Install it when something needs a limit, and nothing else.

Documentation

Read the documentation →

What this package does, how the limiter is wired to a connection and what a fixed window can and cannot promise lives in the NAF documentation. Not sure which packages you need? Start here.

Install

composer require naf/rate-limit

Needs ext-pdo and a database the host binds under PDO::class.

License

MIT. Part of NAF.