1
0
mirror of synced 2026-02-21 12:27:55 +08:00
Files
SnowFlake-IdGenerator/PHP/README.md
2021-04-07 11:51:02 +08:00

51 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ❄ idenerator-php-extension
## 介绍
项目更多介绍参照https://github.com/yitter/idgenerator
## PHP环境
* PHP7 or later
## 安装方式
```shell
git clone https://gitee.com/yitter/idgenerator.git
cd idgenerator/PHP
phpize
./configure --with-php-config=/path/php-config
make
make install
```
## 如何使用PHP
**配置文件配置参数**
```shell
//snowdrift.ini
snowdrift.Method=1 //1 漂移算法 2 传统算法
snowdrift.BaseTime=1582136402000
snowdrift.WorkerId=1 //默认workerid
snowdrift.WorkerIdNum=1 //支持的WorkerId数量默认1不超过(-1L << snowdrift.WorkerIdBitLength) ^ -1L
snowdrift.WorkerIdBitLength=6
snowdrift.SeqBitLength=6 //自增序号位数
snowdrift.MaxSeqNumber=0
snowdrift.MinSeqNumber=0
snowdrift.TopOverCostCount=2000 //最大漂移次数
```
**函数签名**
```php
\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
```
**调用示例**
```php
$id=\SnowDrift::NextId();
$id=\SnowDrift::NextId(3);
$ids=\SnowDrift::NextNumId(10000);
$ids=\SnowDrift::NextNumId(10000,3);
```