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.2 kB

4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 传统算法
  20. snowdrift.BaseTime=1582136402000
  21. snowdrift.WorkerId=1 //默认workerid
  22. snowdrift.WorkerIdNum=1 //支持的WorkerId数量,默认1,不超过(-1L << snowdrift.WorkerIdBitLength) ^ -1L
  23. snowdrift.WorkerIdBitLength=6
  24. snowdrift.SeqBitLength=6 //自增序号位数
  25. snowdrift.MaxSeqNumber=0
  26. snowdrift.MinSeqNumber=0
  27. snowdrift.TopOverCostCount=2000 //最大漂移次数
  28. ```
  29. **函数签名**:
  30. ```php
  31. \SnowDrift::NextId(int $wid=snowdrift.WorkerId):?int //获取单个id,$wid可选,默认值=snowdrift.WorkerId
  32. \SnowDrift::NextNumId(int $num, int $wid=snowdrift.WorkerId):?array //获取$num个id,$wid可选,默认值=snowdrift.WorkerId
  33. ```
  34. **调用示例**
  35. ```php
  36. $id=\SnowDrift::NextId();
  37. $id=\SnowDrift::NextId(3);
  38. $ids=\SnowDrift::NextNumId(10000);
  39. $ids=\SnowDrift::NextNumId(10000,3);
  40. ```