1
0
mirror of synced 2026-02-25 06:19:58 +08:00
Files
SnowFlake-IdGenerator/PHP
2021-04-12 23:04:50 +08:00
..
2021-04-07 11:51:02 +08:00
2021-04-07 11:51:02 +08:00
2021-04-07 11:51:02 +08:00
2021-04-07 11:51:02 +08:00
2021-04-07 11:51:02 +08:00
2021-04-07 15:57:27 +08:00
2021-04-07 11:51:02 +08:00
2021-04-07 11:51:02 +08:00
2021-04-07 11:51:02 +08:00
2021-04-12 23:04:50 +08:00
2021-04-07 11:51:02 +08:00

❄ idgenerator-php-extension

介绍

项目更多介绍参照:https://github.com/yitter/idgenerator

PHP环境

  • PHP7 or later

安装方式

git clone https://gitee.com/yitter/idgenerator.git
cd idgenerator/PHP
phpize
./configure --with-php-config=/path/php-config
make
make install

如何使用PHP

配置文件配置参数

//snowdrift.ini
snowdrift.Method=1 //1 漂移算法 2 传统算法
snowdrift.BaseTime=1582136402000
snowdrift.WorkerId=1 //默认workerid支持参数传递改变实际使用的值范围1~(-1L << snowdrift.WorkerIdBitLength) ^ -1L
snowdrift.WorkerIdBitLength=6 //WorkerId位数默认6。
snowdrift.SeqBitLength=6 //自增序号位数
snowdrift.MaxSeqNumber=0 //默认值为00时自动计算=(-1L << snowdrift.SeqBitLength) ^ -1L需大于MinSeqNumber
snowdrift.MinSeqNumber=5 //默认值为5当配置了MaxSeqNumber时需小于MaxSeqNumber
snowdrift.TopOverCostCount=2000 //最大漂移次数

函数签名

\SnowDrift::NextId(int $wid=snowdrift.WorkerId):?int //获取单个id$wid可选默认值=snowdrift.WorkerId
\SnowDrift::NextNumId(int $num, int $wid=snowdrift.WorkerId):?array //获取$num个id$wid可选默认值=snowdrift.WorkerId

调用示例

$id=\SnowDrift::NextId();
$id=\SnowDrift::NextId(3);

$ids=\SnowDrift::NextNumId(10000);
$ids=\SnowDrift::NextNumId(10000,3);