Snowflake algorithm

Purpose

Generate Unique Number

How to use it

<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 19-1-9
 * Time: 上午10:10
 */
 require './vendor/autoload.php';
 $str = \EasySwoole\Utility\SnowFlake::make(1,1);//Input data center ID (0-31), task process ID (0-31)
var_dump($str);
var_dump(\EasySwoole\Utility\SnowFlake::unmake($str));
 /**
 * Output results:
 * int(194470364728922112)
 * object(stdClass)#3 (4) {
 *   ["timestamp"]=>
 *   int(1532127766018)
 *   ["dataCenterID"]=>
 *   int(1)
 *   ["workerID"]=>
 *   int(1)
 *   ["sequence"]=>
 *   int(0)
 * }
 */

Core object method

Core class:EasySwoole\Utility\SnowFlake

make

Generating Random Numbers Based on Snowflake Algorithms

  • mixed $dataCenterID Data Center

    • mixed $workerID Task process I

    static function make($dataCenterID = 0, $workerID = 0)

    unmake

    Number Generated by Reverse Resolution Snowflake Algorithms

  • mixed $snowFlakeId number

    static function unmake($snowFlakeId)

0 results matching ""

    No results matching ""