PHP code example of imiphp / imi-snowflake

1. Go to this page and download the library: Download imiphp/imi-snowflake library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

imiphp / imi-snowflake example snippets


[
    'components'    =>  [
        // 引入本组件
        'snowflake'    =>  'Imi\Snowflake',
    ],
]

[
    'Snowflake'   =>  [
        'list'  =>  [
            // 可定义多个配置名称
            'testBasic' =>  [
                // 'datacenterId'   => null, // 数据中心ID,未空时为0
                // 'workerId'       => null, // 工作进程ID,为空时取当前进程ID
                // 'startTimeStamp' => null, // 开始时间戳,单位:毫秒
                // 'redisPool'      => null, // Redis 连接池名称,为空取默认连接池
            ],
        ],
    ],
]

$id = \Imi\Snowflake\SnowflakeUtil::id('testBasic');

$array = \Imi\Snowflake\SnowflakeUtil::parseId('testBasic', $id);
var_dump($array);

array(4) {
  ["timestamp"]=>
  string(35) "10100100111111101010001000001110010"
  ["sequence"]=>
  string(12) "000000000000"
  ["workerid"]=>
  string(5) "00000"
  ["datacenter"]=>
  string(5) "00000"
}