PHPackages                             xsdys/limit - 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. xsdys/limit

ActiveLibrary

xsdys/limit
===========

一个限流组件,支持自然周期和非自然周期

v0.0.4(6y ago)0561MITPHP

Since Jun 30Pushed 6y ago1 watchersCompare

[ Source](https://github.com/xingshuwangluo/rate_limit)[ Packagist](https://packagist.org/packages/xsdys/limit)[ RSS](/packages/xsdys-limit/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

限流组件
====

[](#限流组件)

> 自然周期

就是年月日,这样的周期,每(天/月,日...)的开始时间为周期的开始,结束时间为周期结束

> 非自然周期

就是多少秒为一个周期,第一个请求为周期开始,周期秒数后为周期结束,当有新的请求进入后为周期开始(**没有新的请求进入即不开始新的周期**),示例 周期为10秒,第一个请求时间为2014:09:12 00:00:01,那么2014:09:12 00:00:01-2014:09:12 00:00:11为这个周期,但是当00:00:01-2014:09:12 00:00:11之后如果你没有新的请求

简单示例:

```
$config = [
  "host" => "10.0.1.120",
  "password" => null,
  "port" => "6379",
  "database" => 1,
];

 $config = config('database.redis.cache');

$id = 1;
$limit = new \limit\Limit('a1', $id, 10, 'h', true,$config);
dump($limit->used(1)); # 使用成功返回true
dump( $limit->check(1));# 预检是否可用,成功返回true
# 应该先预检后使用
```

初始化
---

[](#初始化)

```
$config = [
  "host" => "10.0.1.120",
  "password" => null,
  "port" => "6379",
  "database" => 1,
];

$config = config('database.redis.cache');

$id = 1;
$limit = new \limit\Limit('user', $id, 10, 'h', true,$config);
```

> 六个参数

- `$name`名字,验证器的名字
- `$id`ID,验证起的ID,与名字一起构成唯一标示,例如:user-1
- `$limit`限流数量,单位周期的限流数量
- `$cycle` 周期,非自然周期为秒数,自然周期为:
    - `y` # 年
    - `m` # 月
    - `d` # 日
    - `w` # 周
    - `h` # 小时
    - `i` # 分钟
    - `s` # 秒
- `$natural`是否为自然周期,默认为`true`
- `$config` 配置项,样式如下,`option`为`Predis`的第二个参数

```
$defalut = [
            'scheme' => 'tcp',
            'host' =>  '127.0.0.1',
            'password' =>  null,
            'port' =>  6379,
            'database' =>  0,
            'option'=>[
                'prefix'=>'limit'
            ]
        ];
```

开始使用
----

[](#开始使用)

- `check(int $value = 0 ):bool`,检查是否有这些值可用,传入的是预检的值,&gt; 剩余值则不可用
- `getRemaining()`,获取剩余可用值
- `getUsed()`,获取已使用值
- `used(int $value=1,$order=null)`,使用一些值
    - `$value`是要使用的值
    - `$order`进行订单判断,**未实现**

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

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

Every ~91 days

Total

4

Last Release

2235d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f3080a28c3e083b56ab8ab461aa83496477dc6f387d45904ae04709b95974a6?d=identicon)[xingshuwangluo](/maintainers/xingshuwangluo)

---

Top Contributors

[![dongasai](https://avatars.githubusercontent.com/u/16734530?v=4)](https://github.com/dongasai "dongasai (9 commits)")

### Embed Badge

![Health badge](/badges/xsdys-limit/health.svg)

```
[![Health](https://phpackages.com/badges/xsdys-limit/health.svg)](https://phpackages.com/packages/xsdys-limit)
```

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M350](/packages/tymon-jwt-auth)[bagisto/bagisto

Bagisto Laravel E-Commerce

26.2k161.6k7](/packages/bagisto-bagisto)[statamic/cms

The Statamic CMS Core Package

4.8k3.2M720](/packages/statamic-cms)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)[concrete5/core

Concrete core subtree split

19159.3k48](/packages/concrete5-core)[alajusticia/laravel-expirable

Make Eloquent models expirable

2193.4k5](/packages/alajusticia-laravel-expirable)

PHPackages © 2026

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