PHPackages                             micoya/php-snowflake-shm - 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. micoya/php-snowflake-shm

ActiveLibrary

micoya/php-snowflake-shm
========================

Generate unique snowflake using PHP and shared memory.

60PHP

Since Jun 3Pushed 2y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Description
-----------

[](#description)

Generate unique snowflake using PHP and shared memory. Maybe it is the fastest resolution.

It requires shmop and sysvsem, so you can't run it on Windows OS.

Performance
-----------

[](#performance)

- 13us per op (WSL2)
- 7us per op (Linux)

Install
-------

[](#install)

```
composer require micoya/php-snowflake-shm
```

Examples
--------

[](#examples)

### Simple Use

[](#simple-use)

```
/**
 * Default snowflake have
 * 41 bit milliseconds timestamps
 * 12 bit machine id
 * 10 bit sequence
*/

// Machine-id is 3
$s = Micoya\PhpSnowflakeShm\SnowflakeFactory::makeShm(3);
echo $s->id();
```

### Custom machine-id length or time

[](#custom-machine-id-length-or-time)

```
$config = new Micoya\PhpSnowflakeShm\Config();

// 16bit machine id , 6bit sequence
$config->machine_id_length = 16;
$config->start_timestamp = 1685603045000;

// use custom config
$s = Micoya\PhpSnowflakeShm\SnowflakeFactory::makeShm(3, $config);
echo $s->id();
```

### Custom machine-id format helper

[](#custom-machine-id-format-helper)

If you want to customize the composition of your machine id, for example, if you need to distinguish between machine and worker, here is a simple tool to use.

```
// 12 bit id includes
// 4 bit machine id, current value is 15
// 8 bit worker id, current value is 1
$helper = new \Micoya\PhpSnowflakeShm\MachineIdHelper(12);
$helper->pushToHigh(4, 15);
$helper->pushToHigh(8, 1);
$result_machine_id = $helper->make();

$config = new Micoya\PhpSnowflakeShm\Config();

$config->machine_id_length = 12;

// use custom config
$s = Micoya\PhpSnowflakeShm\SnowflakeFactory::makeShm($result_machine_id, $config);
echo $s->id();
```

About Unit-Test
---------------

[](#about-unit-test)

Due to some environmental reasons, I didn't use PHPUnit and instead wrote a simple script, Check simple\_test.php.

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![micoya](https://avatars.githubusercontent.com/u/18189537?v=4)](https://github.com/micoya "micoya (6 commits)")

### Embed Badge

![Health badge](/badges/micoya-php-snowflake-shm/health.svg)

```
[![Health](https://phpackages.com/badges/micoya-php-snowflake-shm/health.svg)](https://phpackages.com/packages/micoya-php-snowflake-shm)
```

PHPackages © 2026

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