keep your server calm down
- php 7.3+
- yac 2.0.3+
composer require hi-man/rateguardian
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
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 withguardianOn
- otherwise return
false
- return
RateGuardian::getInstance()->guardianOff($key);
- restart
php-fpm
or php script also cleared guardian setting
RateGuardian::getInstance()->show($key);
- return a array of guardian info
total
the value provided byguardianOn
ttl
the value provided byguardianOn
expired
unix timestamp that calculating periods endedcurrent
current counter value