Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
|
4 years ago | |
---|---|---|
.. | ||
src | 4 years ago | |
tests | 4 years ago | |
travis | 4 years ago | |
.gitignore | 4 years ago | |
.travis.yml | 4 years ago | |
CREDITS | 4 years ago | |
EXPERIMENTAL | 4 years ago | |
LICENSE | 4 years ago | |
README.md | 4 years ago | |
config.m4 | 4 years ago | |
config.w32 | 4 years ago | |
php_snowdrift.h | 4 years ago | |
snowdrift.c | 4 years ago | |
snowdrift.php | 4 years ago |
项目更多介绍参照:https://github.com/yitter/idgenerator
git clone https://gitee.com/yitter/idgenerator.git
cd idgenerator/PHP
phpize
./configure --with-php-config=/path/php-config
make
make install
配置文件配置参数:
//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 //默认值为0,0时自动计算=(-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);
雪花算法中非常好用的数字ID生成器
C C# Pascal Go D other