PHP code example of mitoop / snowflake

1. Go to this page and download the library: Download mitoop/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/ */

    

mitoop / snowflake example snippets


use Mitoop\Snowflake\Snowflake;

// 初始化
$snowflake = new Snowflake('2020-10-24 10:24:00');
// 设置数据中心ID及机器ID(范围: 0-31),默认用随机数
$snowflake->setDatacenterId(1);
$snowflake->setWorkerId(1);
// 设置生成序列号策略 不设置默认就是用的随机数策略
$snowflake->setSequenceStrategy(new RandomSequenceStrategy());
// here we go
$snowflake->id();