PHPackages                             hi-man/rateguardian - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hi-man/rateguardian

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hi-man/rateguardian
===================

local rate limit based on yac

v1.0.0(5y ago)06MITPHP

Since Nov 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/hi-man/rateguardian)[ Packagist](https://packagist.org/packages/hi-man/rateguardian)[ RSS](/packages/hi-man-rateguardian/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

Rate Guardian
=============

[](#rate-guardian)

[![Build Status](https://camo.githubusercontent.com/2f8fe10ea916a0caa353cb7f31375a444740690d347e9cb15ed7882f18f2e1f7/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f68692d6d616e2f72617465677561726469616e2e706e67)](https://travis-ci.org/hi-man/rateguardian)

> keep your server calm down

Requirements
============

[](#requirements)

- php 7.3+
- yac 2.0.3+

Installation
============

[](#installation)

```
composer require hi-man/rateguardian

```

Usage
=====

[](#usage)

step 1 : initialize guardian
----------------------------

[](#step-1--initialize-guardian)

```
RateGuardian::getInstance()->guardianOn($key, $total, $ttl)

```

- `$key` the unique guardian key, such as api pathname, not longer than 41 characters
- `$ttl` in seconds, a counter will be increased in this period
- `$total` the max counter value allowd in `$ttl` second

step 2 : guard api with guardian key
------------------------------------

[](#step-2--guard-api-with-guardian-key)

```
RateGuardian::getInstance()->guard($key);

```

- a `false` value indicates the api is overloaded, application should handle this situation instead of providing service
- return value
    - return `true` if counter less than `$total`
    - return `true` if counter equals `$total`
    - return `true` if `$key` does not be registered with `guardianOn`
    - otherwise return `false`

step 3 : clear guardian
-----------------------

[](#step-3--clear-guardian)

```
RateGuardian::getInstance()->guardianOff($key);

```

- restart `php-fpm` or php script also cleared guardian setting

optional: get guardian info
---------------------------

[](#optional-get-guardian-info)

```
RateGuardian::getInstance()->show($key);

```

- return a array of guardian info
    - `total` the value provided by `guardianOn`
    - `ttl` the value provided by `guardianOn`
    - `expired` unix timestamp that calculating periods ended
    - `current` current counter value

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2044d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/899605?v=4)[hi-man](/maintainers/hi-man)[@hi-man](https://github.com/hi-man)

---

Top Contributors

[![hi-man](https://avatars.githubusercontent.com/u/899605?v=4)](https://github.com/hi-man "hi-man (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hi-man-rateguardian/health.svg)

```
[![Health](https://phpackages.com/badges/hi-man-rateguardian/health.svg)](https://phpackages.com/packages/hi-man-rateguardian)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
