1. Go to this page and download the library: Download bradietilley/php-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/ */
use BradieTilley\Snowflake\Snowflake;
use BradieTilley\Snowflake\SequenceResolvers\FileResolver;
$file = __DIR__.'/snowflake-concurrency.json';
Snowflake::sequenceResolver(new FileResolver($file));
Snowflake::id(); // guaranteed to be unique, even if it's the same microsecond as another process
Snowflake::identifierResolver(function (int $timeSinceConfiguredEpoch, int $sequence, string|null $group) {
if ($group === 'something') {
return 1000000000000000001;
}
return (new SnowflakeIdentifierResolver())->identifier(...func_get_args());
});
Snowflake::id('something'); // 1000000000000000001 custom ID
Snowflake::id(); // 9345345346346345323 regular ID
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.