Search by

phpsoftbox / rate-limiter

Rate limiter component for the PhpSoftBox framework

Maintainers

Package info

github.com/phpsoftbox/rate-limiter

pkg:composer/phpsoftbox/rate-limiter

Transparency log

Statistics

Installs: 115

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2026-08-31 14:51 UTC

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 безопасного идентификатора.