You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.9 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # ❄ idgenerator-php-extension
  2. ## 介绍
  3. 项目更多介绍参照:https://github.com/yitter/idgenerator
  4. ## PHP环境
  5. * PHP7 or later
  6. ## 安装方式
  7. ```shell
  8. git clone https://gitee.com/yitter/idgenerator.git
  9. cd idgenerator/PHP
  10. phpize
  11. ./configure --with-php-config=/path/php-config
  12. make
  13. make install
  14. ```
  15. ## 如何使用(PHP)
  16. **配置文件配置参数**:
  17. ```shell
  18. //snowdrift.ini
  19. snowdrift.Method=1 // 雪花计算方法,(1-漂移算法|2-传统算法),默认1
  20. snowdrift.BaseTime=1582136402000 //基础时间(ms单位),不能超过当前系统时间
  21. snowdrift.WorkerId=1 //机器码,必须由外部设定,最大值 2^WorkerIdBitLength-1
  22. snowdrift.WorkerIdBitLength=6 //机器码位长,默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22)
  23. snowdrift.SeqBitLength=6 //序列数位长,默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22)
  24. snowdrift.MaxSeqNumber=0 //最大序列数(含),设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1]
  25. snowdrift.MinSeqNumber=5 //最小序列数(含),默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位
  26. snowdrift.TopOverCostCount=2000 //最大漂移次数(含),默认2000,推荐范围 500-20000(与计算能力有关)
  27. ```
  28. **函数签名**:
  29. ```php
  30. \SnowDrift::NextId(int $wid=snowdrift.WorkerId):?int //获取单个id,$wid可选,默认值=snowdrift.WorkerId
  31. \SnowDrift::NextNumId(int $num, int $wid=snowdrift.WorkerId):?array //获取$num个id,$wid可选,默认值=snowdrift.WorkerId
  32. ```
  33. **调用示例**
  34. ```php
  35. $id=\SnowDrift::NextId();
  36. $id=\SnowDrift::NextId(3);
  37. $ids=\SnowDrift::NextNumId(10000);
  38. $ids=\SnowDrift::NextNumId(10000,3);
  39. ```