PHPackages                             garengoh/snowflake - 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. garengoh/snowflake

ActiveLibrary

garengoh/snowflake
==================

SnowFlake for yii framework.

v1.0.0(7y ago)318Apache-2.0PHPPHP &gt;=5.5.0

Since Nov 29Pushed 7y ago1 watchersCompare

[ Source](https://github.com/GarenGoh/yii2-snowflake)[ Packagist](https://packagist.org/packages/garengoh/snowflake)[ Docs](https://github.com/GarenGoh/yii2-snowflake.git)[ RSS](/packages/garengoh-snowflake/feed)WikiDiscussions master Synced 2d ago

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

yii2-snowflake
==============

[](#yii2-snowflake)

SnowFlake for yii framework.

Installation
------------

[](#installation)

`composer require garengoh/snowflake`

Usage
-----

[](#usage)

在配置文件`config/web.php`中添加配置,当然你也可以添加到`config/common.php`

```
'components' => [
    'snowflake' => [
        'class' => 'garengoh\snowflake\Snowflake',
        'epoch_offset' => 1514736000000,   //2018-01-01
        //其他可配置的属性(也可以不用配置)
        'timestamp_bits' => 41,     //时间戳位数(算法默认41位,可以使用69年)
        'data_center_bits' => 5,    //IDC(数据中心)编号位数(算法默认5位,最多支持部署32个节点)
        'machine_id_bits' => 5,     //机器编号位数(算法默认5位,最多支持部署32个节点)
        'sequence_bits' => 12,      //计数序列号位数,即一系列的自增id，可以支持同一节点同一毫秒生成多个ID序号(算法默认12位,支持每个节点每毫秒产生4096个ID序号)。
    ]
]
```

项目中调用

```
//只有一台机器(服务器,虚拟机)时
Yii::$app->snowflake->generateID();

//多个数据中心或多台机器时(第一个参数是数据中心编号,第二个机器是机器编号)
Yii::$app->snowflake->generateID(1,3);
```

相关文章
----

[](#相关文章)

- [php实现雪花算法（ID递增)](http://wqiang.net/article/view?id=23)
- [Twitter Snowflake算法详解](https://blog.csdn.net/yangding_/article/details/52768906)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

2723d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c996cb1d1e4545dd53629caae668fd6a6fe0e48d8623525da74e945c1b2c0b49?d=identicon)[GarenGoh](/maintainers/GarenGoh)

---

Top Contributors

[![GarenGoh](https://avatars.githubusercontent.com/u/13014689?v=4)](https://github.com/GarenGoh "GarenGoh (5 commits)")

---

Tags

yii2snowflake

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/garengoh-snowflake/health.svg)

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

###  Alternatives

[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

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