PHPackages                             imiphp/imi-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. imiphp/imi-snowflake

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

imiphp/imi-snowflake
====================

imi 框架的雪花算法生成组件

v2.1.9(2y ago)328.5kMulanPSL-2.0PHP

Since Apr 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/imiphp/imi-snowflake)[ Packagist](https://packagist.org/packages/imiphp/imi-snowflake)[ RSS](/packages/imiphp-imi-snowflake/feed)WikiDiscussions 2.0 Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (23)Used By (0)

imi-snowflake
=============

[](#imi-snowflake)

[![Latest Version](https://camo.githubusercontent.com/f4120e4c58a9215c0474db7f84e2d4fbfe4de41daa77d72a7ed3403029a09e6c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d697068702f696d692d736e6f77666c616b652e737667)](https://packagist.org/packages/imiphp/imi-snowflake)[![Php Version](https://camo.githubusercontent.com/4a5c2ab20974058a8bab53ecb30ac4c2e6bb961df6229b7386fdc097ab53dfa8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e342d627269676874677265656e2e737667)](https://secure.php.net/)[![Swoole Version](https://camo.githubusercontent.com/f4210afc3f396a720a75802010218d847f3ba4f7ae5182c570b1fb2504ec9ec3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73776f6f6c652d2533453d342e372e302d627269676874677265656e2e737667)](https://github.com/swoole/swoole-src)[![IMI License](https://camo.githubusercontent.com/5287f4b6011255fd52c4a108abc532326c452b694cf492b5b160d39df299888b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f696d697068702f696d692d736e6f77666c616b652e737667)](https://github.com/imiphp/imi-snowflake/blob/master/LICENSE)

介绍
--

[](#介绍)

imi 框架的雪花算法生成组件

> 本仓库仅用于浏览，不接受 issue 和 Pull Requests，请前往：

Composer
--------

[](#composer)

本项目可以使用composer安装，遵循psr-4自动加载规则，在你的 `composer.json` 中加入下面的内容:

```
{
    "require": {
        "imiphp/imi-snowflake": "~2.0.0"
    }
}
```

然后执行 `composer update` 安装。

使用
--

[](#使用)

在项目 `config/config.php` 中配置：

```
[
    'components'    =>  [
        // 引入本组件
        'snowflake'    =>  'Imi\Snowflake',
    ],
]
```

### 配置

[](#配置)

配置 `@app.beans`：

```
[
    'Snowflake'   =>  [
        'list'  =>  [
            // 可定义多个配置名称
            'testBasic' =>  [
                // 'datacenterId'   => null, // 数据中心ID，未空时为0
                // 'workerId'       => null, // 工作进程ID，为空时取当前进程ID
                // 'startTimeStamp' => null, // 开始时间戳，单位：毫秒
                // 'redisPool'      => null, // Redis 连接池名称，为空取默认连接池
            ],
        ],
    ],
]
```

### 生成ID

[](#生成id)

```
$id = \Imi\Snowflake\SnowflakeUtil::id('testBasic');
```

### 解析ID

[](#解析id)

```
$array = \Imi\Snowflake\SnowflakeUtil::parseId('testBasic', $id);
var_dump($array);
```

处理结果格式：

```
array(4) {
  ["timestamp"]=>
  string(35) "10100100111111101010001000001110010"
  ["sequence"]=>
  string(12) "000000000000"
  ["workerid"]=>
  string(5) "00000"
  ["datacenter"]=>
  string(5) "00000"
}
```

免费技术支持
------

[](#免费技术支持)

QQ群：17916227 [![点击加群](https://camo.githubusercontent.com/75b53e353bb9e5064662e185a6d39f4bb88c4e45bd3a1240ddf599525edb6afa/68747470733a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67 "点击加群")](https://jq.qq.com/?_wv=1027&k=5wXf4Zq)，如有问题会有人解答和修复。

运行环境
----

[](#运行环境)

- [PHP](https://php.net/) &gt;= 7.4
- [Composer](https://getcomposer.org/) &gt;= 2.0
- [Swoole](https://www.swoole.com/) &gt;= 4.1.0

版权信息
----

[](#版权信息)

`imi-snowflake` 遵循 MIT 开源协议发布，并提供免费使用。

鸣谢
--

[](#鸣谢)

感谢 [godruoyi/php-snowflake](https://github.com/godruoyi/php-snowflake) 为 imi-snowflake 提供算法驱动！

捐赠
--

[](#捐赠)

[![](https://camo.githubusercontent.com/d6289b746e049310225a52ee7d4f9aab71cf9df63a3341cb037e7ec09b31ea1f/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f696d697068702f696d6940322e302f7265732f7061792e706e67)](https://camo.githubusercontent.com/d6289b746e049310225a52ee7d4f9aab71cf9df63a3341cb037e7ec09b31ea1f/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f696d697068702f696d6940322e302f7265732f7061792e706e67)

开源不求盈利，多少都是心意，生活不易，随缘随缘……

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 96.6% 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 ~62 days

Total

23

Last Release

851d ago

Major Versions

v1.0.1 → v2.0.02021-08-20

2.1.x-dev → 3.0.x-dev2024-01-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f917bb42280d114c53cebadc2942a13ee03abe14971089f88895e266d637169?d=identicon)[Yurunsoft](/maintainers/Yurunsoft)

---

Top Contributors

[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (28 commits)")[![NHZEX](https://avatars.githubusercontent.com/u/14545600?v=4)](https://github.com/NHZEX "NHZEX (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aimeos/macro

Customize classes using closures

2.3k131.7k5](/packages/aimeos-macro)[nodejs-php-fallback/stylus

PHP wrapper to execute stylus node package or fallback to a PHP alternative

11135.5k4](/packages/nodejs-php-fallback-stylus)

PHPackages © 2026

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