PHP code example of alexeyco / snowflake

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

    

alexeyco / snowflake example snippets




use SnowFlake\Node;

// Set up custom epoch and node
Node::getInstance()
    ->setEpoch(new \DateTime('2000-01-01 00:00:00')) // Default is 2006-03-21:20:50:14 GMT
    ->setNode(1); // Default is 0; can be between 0 and 1023

$id = Node::getInstance()->generate();

var_dump($id->toInt());
// => 6375898920270168065

var_dump($id->toString();
// => 1cfvnjc093zlt



use SnowFlake\Parser;

$id = Parser::fromString('1cfvnjc093zlt');

var_dump($id->toInt());
// ==> 6375898920270168065