phpsoftbox / rate-limiter
Rate limiter component for the PhpSoftBox framework
Requires
- php: ^8.5
- psr/simple-cache: ^3.0
Requires (Dev)
- phpunit/phpunit: ^11.2
Suggests
- ext-redis: Required when RedisRateLimiter is used with the PhpRedis client.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-08-31 14:51:44 UTC
README
Компонент реализует fixed-window rate limiting.
Production
Для нескольких workers используйте атомарный storage:
$limiter = new RedisRateLimiter($phpRedisClient);
RedisRateLimiter выполняет increment и установку TTL одним Lua script.
Альтернативный backend можно подключить через AtomicRateLimitStoreInterface и
AtomicStoreRateLimiter.
SimpleCacheRateLimiter использует обычный PSR-16 get/set, поэтому подходит
только для development, тестов или гарантированно single-process окружения.
RateLimitResult содержит:
limit;remaining;retryAfterSeconds— относительное ожидание;resetAt— абсолютный Unix timestamp.
Ключи
HashRateLimitKeyNormalizer формирует PSR-16-safe ключ из namespace и SHA-256:
$key = $normalizer->normalize($rawKey, 'node_api');
Raw credentials нельзя включать даже в исходный ключ. Используйте Node ID, credential selector или необратимый hash безопасного идентификатора.