hydrakit / throttle
Request rate limiting as PSR-15 middleware, counted in a shared store.
Requires
- php: >=8.4
- hydrakit/cache: ^0.31
- hydrakit/core: ^0.31
- hydrakit/http: ^0.31
- psr/clock: ^1.0
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^3.0
Requires (Dev)
- nyholm/psr7: ^1.8
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main / 0.31.x-dev
- v0.31.2
- v0.31.1
- v0.31.0
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.0
- v0.26.0
- v0.25.0
- v0.24.0
- v0.23.0
- v0.22.1
- v0.22.0
- v0.21.0
- v0.20.0
- v0.19.0
- v0.18.0
- v0.17.0
- v0.16.0
- v0.15.0
- v0.14.0
- v0.13.0
- v0.12.0
- v0.11.0
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.17
- v0.9.16
- v0.9.15
- v0.9.14
- v0.9.13
- v0.9.12
- v0.9.11
- v0.9.10
- v0.9.9
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.1
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.8
- v0.5.7
- v0.5.6
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.1
This package is auto-updated.
Last update: 2026-10-27 22:06:12 UTC
README
Part of the Hydra PHP framework. Documentation: hydra.williamhleucka.com/docs.
Read-only mirror.
hydrakit/throttleis developed in hydra-foundation/hydra underpackages/throttle, and republished here on every push. A commit pushed to this repository is overwritten by the next one; issues are disabled for that reason, and a pull request opened here cannot be merged. Both belong upstream.
Request rate limiting as PSR-15 middleware. A RateLimitPolicy is a budget
(a name, a count and a window in seconds); RateLimiter spends one request
against it and refuses with a TooManyRequestsException carrying Retry-After
once it is gone. Counting happens in hydrakit/cache's StoreInterface, whose
increment() opens the window on the first hit and never re-arms it, so a
steady stream cannot hold a budget open past its limit.
RateLimitMiddleware is the application-wide budget, configured from
RATE_LIMIT, RATE_LIMIT_WINDOW and RATE_LIMIT_ENABLED. Place it inside
the error handler: an unreachable store raises, and the limiter refuses traffic
it cannot meter rather than serving it unmetered, which only renders as a 500 if
something is there to catch it. A tighter budget for one route is a middleware
of its own, named in that route's #[Route(middleware: [...])], holding its own
policy and calling the same RateLimiter.
Who the client is comes from hydrakit/http's ClientIpResolver, never from
the forwarding header directly: a limiter that reads X-Forwarded-For itself is
one a caller resets by prepending a hop.