mini_quota_worker.php 611 B

123456789101112131415161718
  1. <?php
  2. require dirname(__DIR__, 2) . '/vendor/autoload.php';
  3. \Dotenv\Dotenv::createUnsafeMutable(dirname(__DIR__, 2))->load();
  4. \support\App::loadAllConfig(['route']);
  5. if (!preg_match('/^mini-protection-test:[a-f0-9]{24}:concurrent$/D', $argv[1] ?? '')) {
  6. throw new RuntimeException('Expected isolated test key');
  7. }
  8. $accepted = 0;
  9. for ($i = 0; $i < 20; $i++) {
  10. $result = (new \app\miniapi\protection\RedisQuota())->consume([
  11. ['key' => $argv[1], 'limit' => 35, 'seconds' => 60, 'cost' => 1, 'rule' => 'concurrent'],
  12. ]);
  13. if ($result[0] === 0) {
  14. $accepted++;
  15. }
  16. }
  17. echo $accepted;