PHPackages                             artnum/snowflake53 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. artnum/snowflake53

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

artnum/snowflake53
==================

Generate unique 53 bits snowflake IDs

v1.1.0(1y ago)114MITPHPPHP &gt;=8.2

Since Mar 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/artnum/snowflake53)[ Packagist](https://packagist.org/packages/artnum/snowflake53)[ RSS](/packages/artnum-snowflake53/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (11)Used By (0)

Snowflake53
===========

[](#snowflake53)

A trait to generate 53 bits snowflake id to fit into js Number.MAX\_SAFE\_INTEGER. Sequence counting is done with shared memory and machine ID comes from environment variable or parameters It also possible to generate 64 bits snowflake id.

It dosen't require any external infrastructure (like Memcached or Redis or ...) to keep sequence counting as it is done by shared memory and use semaphore for locking. So other processes can tap into the sequence counting too :)

Install
-------

[](#install)

Via composer :

```
$ composer require artnum/snowflake53

```

Usage
-----

[](#usage)

```
require_once 'vendor/autoload.php';

use Snowflake53\ID;

class IDGen {
    use ID;
}

$gen = new IDGen();
echo $gen->get53() . PHP_EOL;
echo $gen->get64() . PHP_EOL;
```

All functions are declared as static, so it is possible to use without a class instance.

```
require_once 'vendor/autoload.php';

use Snowflake53\ID;

class IDGen {
    use ID;
}

echo IDGen::get53() . PHP_EOL;
echo IDGen::get64() . PHP_EOL;
```

You can destroy, if you choose to, shared memory semgent and semaphore by calling `destroySHM`:

```
require_once 'vendor/autoload.php';

use Snowflake53\ID;

class IDGen {
    use ID;
}

IDGen::destroySHM();
```

Shared memory path
------------------

[](#shared-memory-path)

Shared memory use a file path as identity. By default it is `__FILE__`. But if you use this in several different places on your server but still want all ID to be in sequence, you can set the public static variable $SHMPath to the path you want. The file **must** exist.

```
require_once 'src/Snowflake53.php';

use Snowflake53\ID;

class IDGen {
    use ID;
}

IDGen::$SHMPath = '/tmp/snowflake53';
echo IDGen::get53() . PHP_EOL;
echo IDGen::get64() . PHP_EOL;

$gen = new IDGen();
$gen::$SHMPath = '/tmp/snowflake53';
echo $gen->get53() . PHP_EOL;
echo $gen->get64() . PHP_EOL;
```

Machine ID
----------

[](#machine-id)

Machine ID can be passed as argument of `get53` or `get64`. If not, it will try to get the ID from environment variable `SNOWFLAK53_MACHINE_ID`, `SNOWFLAKE64_MACHINE_ID` or `SNOWFLAKE_MACHINE_ID`. When getting a 53 bits ID, `SNOWFLAK53_MACHINE_ID` will be look at and then `SNOWFLAKE_MACHINE_ID`, when getting a 64 bits ID it's the opposite (first `SNOWFLAKE64_MACHINE_ID` and then `SNOWFLAKE_MACHINE_ID`).

The idea behind that is you set a unique machine for 64 and 53 bits and so, you use `SNOWFLAKE_MACHINE_ID` or you have a different machine ID for 53 bits or 64 bits and so you set `SNOWFLAKE53_MACHINE_ID` and `SNOWFLAKE64_MACHINE_ID`.

License
-------

[](#license)

Under [MIT license](https://opensource.org/license/mit).

Developer
---------

[](#developer)

- Etienne Bagnoud

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance47

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~88 days

Total

10

Last Release

389d ago

Major Versions

v0.0.5 → v1.0.02024-04-26

PHP version history (2 changes)v0.0.1PHP ^8.2

v0.0.2PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9168a01041c3c57948f819c4f05fc72120f4bd11b08f2dae72f3fdd06c4c9c8?d=identicon)[artnum](/maintainers/artnum)

---

Top Contributors

[![artnum](https://avatars.githubusercontent.com/u/27413243?v=4)](https://github.com/artnum "artnum (13 commits)")

---

Tags

id-generationphp82semaphoreshared-memorysnowflakesnowflake-idtraitweb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/artnum-snowflake53/health.svg)

```
[![Health](https://phpackages.com/badges/artnum-snowflake53/health.svg)](https://phpackages.com/packages/artnum-snowflake53)
```

###  Alternatives

[tedivm/jshrink

Javascript Minifier built in PHP

76137.7M138](/packages/tedivm-jshrink)[phpseclib/mcrypt_compat

PHP 5.x-8.x polyfill for mcrypt extension

28029.7M34](/packages/phpseclib-mcrypt-compat)[phpbench/container

Simple, configurable, service container.

1512.9M6](/packages/phpbench-container)[georgringer/numbered-pagination

Improved pagination for TYPO3

281.3M13](/packages/georgringer-numbered-pagination)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
