PHP code example of grantholle / scru64

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

    

grantholle / scru64 example snippets


use GrantHolle\Scru64\Scru64;

$id = Scru64::generate();

echo $id;          // "0w2sp3sj5t2i"
echo $id->value;   // 117281148432446826

use GrantHolle\Scru64\Scru64;
use GrantHolle\Scru64\Scru64Generator;

Scru64::setGenerator(Scru64Generator::fromNodeSpec('42/8'));

Scru64::generate();

use GrantHolle\Scru64\Scru64Generator;

$generator = new Scru64Generator(nodeId: 42, nodeIdSize: 8);
// or
$generator = Scru64Generator::fromNodeSpec('42/8');

$id = $generator->generate();

use GrantHolle\Scru64\Scru64Id;

$id = Scru64Id::fromString('0u2pf62ji4b9');  // case-insensitive
$id = new Scru64Id(109959589539758421);
$id = Scru64Id::fromParts(timestamp: 6554000, nodeCtr: 0x2a0000);

(string) $id;      // "0u2pf62ji4b9"
$id->value;        // 109959589539758421
$id->timestamp();  // Unix time in 256 ms units
$id->nodeCtr();    // combined 24-bit node ID + counter field
bash
SCRU64_NODE_SPEC=42/8 php app.php