Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 17, 2025

Implements a comprehensive rate limiting component supporting Fixed Window, Sliding Window, Token Bucket, and Leaky Bucket algorithms with Redis + Lua atomic operations.

Core Implementation

  • Algorithms (src/rate-limit/src/Algorithm/)

    • FixedWindowRateLimiter - Counter-based with fixed time windows
    • SlidingWindowRateLimiter - Sorted set with precise time tracking
    • TokenBucketRateLimiter - Burst-friendly with constant refill
    • LeakyBucketRateLimiter - Burst-smoothing with constant rate
  • Lua Scripts (src/rate-limit/src/Storage/LuaScripts.php)

    • Atomic Redis operations for all algorithms
    • Race-condition free in distributed environments
  • Factory (src/rate-limit/src/RateLimiterFactory.php)

    • Algorithm selection via make(string $algorithm)
    • Instance caching per algorithm-connection pair

Integration Methods

Annotations

use FriendsOfHyperf\RateLimit\Annotation\RateLimit;

#[RateLimit(key: "api:{ip}", maxAttempts: 60, decay: 60, algorithm: "sliding_window")]
public function index() { }

Middleware

class ApiRateLimitMiddleware extends RateLimitMiddleware
{
    protected int $maxAttempts = 60;
    protected string $algorithm = 'sliding_window';
}

Direct Usage

$limiter = $factory->make('token_bucket');
if ($limiter->tooManyAttempts($key, $maxAttempts, $decay)) {
    throw new RateLimitException('Rate limit exceeded');
}

Key Features

  • Dynamic Key Resolution - Placeholders: {ip}, {user_id}, method arguments
  • Rate Limit Headers - Standard X-RateLimit-* headers on responses
  • Config Center Ready - Dynamic configuration support via Hyperf config system
  • Type Safe - PHP 8.1+ with strict types throughout

Files Changed

  • Added src/rate-limit/ with 13 PHP classes, examples, tests
  • Updated composer.json - autoload, replace, ConfigProvider registration
  • Added test group to tests/Pest.php
  • Documentation in English and Chinese

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/CarbonPHP/carbon-doctrine-types/zipball/99f76ffa36cce3b70a4a6abce41dba15ca2e84cb
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/CarbonPHP/carbon/zipball/9228ce90e1035ff2f0db84b40ec2e023ed802075
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/3ba905c11371512af9d9bdd27d99b782216b6945
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/JetBrains/phpstorm-attributes/zipball/64de815a4509c29e00d5e3474087fd24c171afc2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/7569658f91e475ec93b99bd5964b059ad1336dcf
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/PHP-DI/PhpDocReader/zipball/66daff34cbd2627740ffec9469ffbac9f8c8185c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/Seldaek/jsonlint/zipball/1748aaf847fc731cfad7725aec413ee46f0cc3a2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/Seldaek/phar-utils/zipball/ea2f4014f163c1be4c601b9b7bd6af81ba8d701c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/Seldaek/signal-handler/zipball/04a6112e883ad76c0ada8e4a9f7520bbfdb6bb98
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/aws/aws-sdk-php/zipball/c3b6f1fcba1b5da263e701354638a7086dbb09ec
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/awslabs/aws-crt-php/zipball/d71d9906c7bb63a28295447ba12e74723bd3730e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/barryvdh/ReflectionDocBlock/zipball/d103774cbe7e94ddee7e4870f97f727b43fe7201
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/composer/ca-bundle/zipball/1905981ee626e6f852448b7aaa978f8666c5bc54
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/composer/class-map-generator/zipball/ba9f089655d4cdd64e762a6044f411ccdaec0076
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/composer/composer/zipball/35cb6d47d03b0cae52dc12d686f941365b20f08b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/composer/metadata-minifier/zipball/c549d23829536f0d0e984aaabbf02af91f443207
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/composer/semver/zipball/198166618906cb2de69b95d7d47e5fa8aa1b2b95
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/composer/spdx-licenses/zipball/edf364cefe8c43501e21e88110aac10b284c3c9f
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/composer/xdebug-handler/zipball/6c1925561632e83d60a44492e0b344cf48ab85ef
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/doctrine/deprecations/zipball/459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/doctrine/event-manager/zipball/b680156fa328f1dfd874fd48c7026c41570b9c6e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/doctrine/inflector/zipball/6d6c96277ea252fc1304627204c3d5e6e15faa3b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/doctrine/lexer/zipball/861c870e8b75f7c8f69c146c7f89cc1c0f1b49b6
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/elastic/elastic-transport-php/zipball/1d476af5dc0b74530d59b67d5dd96ee39768d5a4
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/elastic/elasticsearch-php/zipball/1771284cb43a7b653634d418b6f5f0ec84ff8a6d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/ergebnis/composer-normalize/zipball/86dc9731b8320f49e9be9ad6d8e4de9b8b0e9b8b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/ergebnis/json-normalizer/zipball/77961faf2c651c3f05977b53c6c68e8434febf62
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/ergebnis/json-pointer/zipball/43bef355184e9542635e35dd2705910a3df4c236
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/ergebnis/json-printer/zipball/211d73fc7ec6daf98568ee6ed6e6d133dee8503e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/ergebnis/json-schema-validator/zipball/b739527a480a9e3651360ad351ea77e7e9019df2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/ergebnis/json/zipball/7b56d2b5d9e897e75b43e2e753075a0904c921b1
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/ezyang/htmlpurifier/zipball/b287d2a16aceffbf6e0295559b39662612b77fcf
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/filp/whoops/zipball/d2102955e48b9fd9ab24280a7ad12ed552752c4d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/google/recaptcha/zipball/56522c261d2e8c58ba416c90f81a4cd9f2ed89b9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/googleapis/common-protos-php/zipball/0a399e6f39576e39ae9b66d3c704ae294afab1dc
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/guzzle/guzzle/zipball/b51ac707cfa420b7bfd4e4d5e510ba8008e822b4
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/guzzle/promises/zipball/481557b130ef3790cf82b713667b43030dc9c957
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/guzzle/psr7/zipball/21dc724a0583619cd1652f673303492272778051
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/guzzle/uri-template/zipball/4f4bbd4e7172148801e76e3decc1e559bdee34e1
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/huangdijia/php-coding-standard/zipball/11e5e9e6f5a2bfdf6038ecbe2a5333c539a5ae1b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/amqp/zipball/73cf773449b238697434f609d6a1e0345bbe6759
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/async-queue/zipball/aab0415cda56fe427772510a9a32a4fbcbba33af
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/cache/zipball/02ee5919c21a883f8abcdc6da10a40370ba69d19
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/code-parser/zipball/cc6ee7f865473df17d18962caf9ec5eda98d9174
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/codec/zipball/6e69634d60d12bad46e3395471b419c032eefc76
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/collection/zipball/8f43bd741ffae01208401791687830c6df32da83
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/command/zipball/848ae09136c2021d306a51a753292af4a6155616
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/conditionable/zipball/051f3a696b444267298fec58075810169818e9a3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/config-center/zipball/d781d0a7cebf9ddc16d5fa6969dd788b1bdcc333
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/config/zipball/c5e787f3dec38a183e9fb96087a086b731e048ff
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/consul/zipball/8ef4c7380dfabe6dec1c2cafcda174123c4b073a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/context/zipball/a8cb6d27c5b85b44ce8d1e58d1ccfe1a1831b2f5
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/contract/zipball/24d11e962033a1a44468df6318f9a2c2c0b8f99e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/coordinator/zipball/ea3c40ed9a8803703c5851e24d12c420f129e947
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/coroutine/zipball/6eef27161d44c7c2ac353591b7428a100aa87797
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/crontab/zipball/894a9f18f9767fbc62bcfaedaa45fd1ff075c7f0
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/database/zipball/a8d292078e6f2a48a52cf5a76dc007b83edb08db
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/db-connection/zipball/9db060c0e53ff704ac65ef30d8c5088973ba5612
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/db/zipball/64871a72c564cc41c636b0cd82160ae3ffa87694
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/devtool/zipball/cbcf9c16c07868a205435ac8aab54a7dc1a849a6
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/di/zipball/4020913f3f9497bf5067f280374186b10ce8c2b6
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/engine-contract/zipball/26a18ec0375147546bf9702b0fd737fdd2cec1d6
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/engine/zipball/6595d2659ce7ebb940b8740a00ecd199128398f0
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/event/zipball/ba60b087bc4dd54a7edf39308dd5eb4b82bd3f0e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/framework/zipball/c2a980881d77e349c52b08ee6d63244d025c89e5
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/macroable/zipball/8aa26c1252b48673a7c22df2ef5dc8894bc340f2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/model-listener/zipball/15238b2026158036993939c1b664f3f76f02a855
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/pipeline/zipball/cd01fbc15daab350c70182d73200924040e0cd1e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/pool/zipball/a4b763723103636cca3afb9f85c620ae02c1a33c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/process/zipball/6fdd31c373b9fb9c99c91fc46d009b8748668b37
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/stdlib/zipball/a6836bed94a058090177de0a5038228fba383f4e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/stringable/zipball/aa20da362306cdc64ed7ee2cc7c2251642631557
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/support/zipball/e40585a21604f2210237d25e4c851c4acc0b1803
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/hyperf/tappable/zipball/2ece958479d44e574fad3f1ab16ebcfbf4eaf28f
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/jmespath/jmespath.php/zipball/a2a865e05d5f420b50cc2f85bb78d565db12a6bc
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/jsonrainbow/json-schema/zipball/fd8e5c6b1badb998844ad34ce0abcd71a0aeb396
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/localheinz/diff/zipball/33bd840935970cda6691c23fc7d94ae764c0734c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/marc-mabe/php-enum/zipball/bb426fcdd65c60fb3638ef741e8782508fda7eef
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/opentelemetry-php/api/zipball/610b79ad9d6d97e8368bcb6c4d42394fbb87b522
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/opentelemetry-php/context/zipball/d4c4470b541ce72000d18c339cfee633e4c8e0cf
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/paragonie/constant_time_encoding/zipball/d5b01a39b3415c2cd581d3bd3a3575c1ebbd8e77
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/pestphp/pest-plugin/zipball/e05d2859e08c2567ee38ce8b005d044e72648c0b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-amqplib/php-amqplib/zipball/9f50fe69a9f1a19e2cb25596a354d705de36fe59
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/http-message-util/zipball/9d94dc0154230ac39e5bf89398b324a86f63f765
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-http/discovery/zipball/82fe4c73ef3363caed49ff8dd1539ba06044910d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-http/httplug/zipball/5cad731844891a4c282f3f3e1b582c46839d22f4
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-http/promise/zipball/fc85b1fba37c169a69a07ef0d5a8075770cc1f83
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/phpseclib/phpseclib/zipball/9d6ca36a6c2dd434765b1071b2644a1c683b385d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/57d440fc54a00fda5b8781e8d9bf0140ea6d8e52
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/reactphp/cache/zipball/d47c472b64aa5608225f47965a484b75c7817d5b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/reactphp/child-process/zipball/1721e2b93d89b745664353b9cfc8f155ba8a6159
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/reactphp/dns/zipball/eb8ae001b5a455665c89c1df97f6fb682f8fb0f5
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/reactphp/promise/zipball/23444f53a813a3296c1368bb104793ce8d88f04a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/reactphp/socket/zipball/23e4ff33ea3e160d2d1f59a0e6050e4b0fb0eac1
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/schmittjoh/php-option/zipball/638a154f8d4ee6a5cfa96d6a34dfbe0cffa9566d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/environment/zipball/8074dbcd93529b357029f5cc5058fd3e43666984
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/exporter/zipball/0735b90f4da94969541dac1da743446e276defa6
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/987bafff24ecc4c9ac418cab1145b96dd6e9cbd9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/47e34210757a2f37a97dcd207d032e1b01e64c7a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/59eb412e93815df44f05f342958efa9f46b1e586
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/event-dispatcher/zipball/b7dc69e71de420ac04bc9ab830cf3ffebba48191
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/filesystem/zipball/e9bcfd7837928ab656276fe00464092cc9e1826a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/finder/zipball/9f696d2f1e340484b4683f7853b273abff94421f
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/options-resolver/zipball/0ff2f5c3df08a395232bbc3c2eb7e84912df911d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-php82/zipball/5d2ed36f7734637dacc025f179698031951b1692
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-php84/zipball/d8ced4d875142b6a7426000426b8abc631d6b191
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/process/zipball/f24f8f316367b30810810d4eb30c543d7003ff3b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/stopwatch/zipball/5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/translation-contracts/zipball/65a8bc82080447fae78373aa10f8d13b38338977
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/translation/zipball/c8559fe25c7ee7aa9d28f228903a46db008156a4
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/vinkla/hashids/zipball/197171016b77ddf14e259e186559152eb3f8cf33
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/vlucas/phpdotenv/zipball/24ac4c74f91ee2c193fa1aaa5c249cb0822809af
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KeFNa2 /usr/bin/composer install --no-interaction --prefer-dist (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

设计一个限流组件
组件名:rate-limit
算法支持:滑动窗口 / 固定窗口 / Token Bucket / Leaky Bucket
特性:注解、AOP、Middleware、动态配置中心、Redis + Lua 原子化


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com>
@friendsofhyperf friendsofhyperf deleted a comment from coderabbitai bot Nov 17, 2025
Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com>
@coderabbitai
Copy link

coderabbitai bot commented Nov 17, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Comment @coderabbitai help to get the list of available commands and usage tips.

Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com>
Copilot AI changed the title [WIP] Add rate limit component with multiple algorithms Add rate-limit component with 4 algorithms, annotations, AOP, and middleware Nov 17, 2025
Copilot AI requested a review from huangdijia November 17, 2025 16:22
Co-Authored-By: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive rate limiting component for Hyperf with support for four different algorithms (Fixed Window, Sliding Window, Token Bucket, and Leaky Bucket), providing multiple integration methods through annotations, AOP aspects, and middleware.

Key Changes:

  • Added complete rate-limit component with 4 rate limiting algorithms using Redis + Lua for atomic operations
  • Implemented annotation-based rate limiting via AOP with dynamic key placeholder support
  • Created abstract middleware for HTTP request rate limiting with customizable response handling

Reviewed Changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
src/rate-limit/src/Algorithm/*.php Four rate limiter implementations (Fixed Window, Sliding Window, Token Bucket, Leaky Bucket)
src/rate-limit/src/Storage/LuaScripts.php Redis Lua scripts for atomic rate limit operations
src/rate-limit/src/Aspect/RateLimitAspect.php AOP aspect for annotation-based rate limiting with placeholder resolution
src/rate-limit/src/Middleware/RateLimitMiddleware.php Abstract middleware for HTTP rate limiting with IP detection
src/rate-limit/src/Annotation/RateLimit.php Annotation class for declaring rate limits on methods
src/rate-limit/src/RateLimiterFactory.php Factory for creating and caching rate limiter instances
src/rate-limit/src/Contract/RateLimiterInterface.php Interface defining rate limiter contract
src/rate-limit/src/ConfigProvider.php Hyperf configuration provider registering the aspect
src/rate-limit/src/Exception/RateLimitException.php Exception thrown when rate limits are exceeded
src/rate-limit/README.md Comprehensive documentation with usage examples
src/rate-limit/composer.json Package definition with dependencies
tests/RateLimit/*.php Basic unit tests for factory, Lua scripts, and annotations
tests/Pest.php Added rate-limit test group
composer.json Registered new component in monorepo autoload and config
docs/*/guide/start/components.md Updated component lists across all language docs
src/closure-job/* Added new closure-job component (separate feature)

@huangdijia huangdijia marked this pull request as ready for review November 18, 2025 02:28
@huangdijia huangdijia merged commit 5c17075 into main Nov 18, 2025
22 checks passed
@huangdijia huangdijia deleted the copilot/add-rate-limit-component branch November 18, 2025 02:30
huangdijia added a commit that referenced this pull request Nov 18, 2025
…dleware (#1014)

Co-Authored-By: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-Authored-By: huangdijia <8337659+huangdijia@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants