PHPackages                             marcinjean/minisnowflake - 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. marcinjean/minisnowflake

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

marcinjean/minisnowflake
========================

A lightweight, case-insensitive, short ID generator using a mini Snowflake algorithm.

1.1(1y ago)13MITPHPPHP &gt;=7.4

Since Apr 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/MarcinJean/MiniSnowFlake)[ Packagist](https://packagist.org/packages/marcinjean/minisnowflake)[ Docs](https://github.com/MarcinJean/MiniSnowFlake)[ GitHub Sponsors](https://github.com/marcinjean)[ RSS](/packages/marcinjean-minisnowflake/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

MiniSnowflake
=============

[](#minisnowflake)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

A lightweight, case-insensitive, 9-character unique ID generator based on a mini Snowflake algorithm, written in PHP.

Built for high-performance systems needing short, collision-resistant IDs without long UUIDs.

---

Features
--------

[](#features)

- ✅ 9-character alphanumeric IDs
- ✅ Based on a customizable epoch (like Twitter Snowflake)
- ✅ No collision up to 256 IDs per millisecond
- ✅ Case-insensitive for user input
- ✅ Optional CLI tool for generating IDs
- ✅ Fully unit-tested with PHPUnit
- ✅ PSR-4 autoloaded, Composer ready

---

Installation
------------

[](#installation)

Install via Composer:

```
composer require marcinjean/minisnowflake
```

---

Basic Usage
-----------

[](#basic-usage)

```
use MarcinJean\MiniSnowflake\MiniSnowflake;

// Generate a new ID
$id = MiniSnowflake::generateId();

echo $id; // Example: "00D2D87XE"

// Validate an ID
if (MiniSnowflake::isValidId($id)) {
    echo "ID is valid!";
}

// Decode an ID
$data = MiniSnowflake::decodeId($id);

print_r($data);
/*
Array
(
    [timestamp] => 1714256780000
    [datetime] => 2025-04-27 22:19:40
    [sequence] => 123
)
*/
```

---

Custom Epoch
------------

[](#custom-epoch)

By default, IDs are generated relative to **January 1st, 2025**.

You can **customize the epoch** globally:

```
// Set a custom epoch (in milliseconds)
MiniSnowflake::setEpoch(strtotime('2024-01-01 00:00:00') * 1000);

// Reset to default epoch (2025-01-01)
MiniSnowflake::resetEpoch();
```

Or pass a **custom epoch per call**:

```
$customEpoch = strtotime('2023-01-01 00:00:00') * 1000;

$id = MiniSnowflake::generateId($customEpoch);
$data = MiniSnowflake::decodeId($id, $customEpoch);
```

---

CLI Usage
---------

[](#cli-usage)

After installing:

```
php bin/generate-id.php
```

Example output:

```
Generated ID: 00D2D87XE
Decoded Info:
- Timestamp: 1714256780000
- Datetime: 2025-04-27 22:19:40
- Sequence: 123

```

You can also specify a custom epoch:

```
php bin/generate-id.php --epoch=1704067200000
```

---

Running Tests
-------------

[](#running-tests)

This package is fully unit-tested with PHPUnit.

Install dev dependencies:

```
composer install
```

Run tests:

```
composer test
```

You should see:

```
OK (4 tests, 10 assertions)

```

---

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

---

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance51

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

376d ago

### Community

Maintainers

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

---

Top Contributors

[![MarcinJean](https://avatars.githubusercontent.com/u/82165361?v=4)](https://github.com/MarcinJean "MarcinJean (16 commits)")

---

Tags

idslaravelphpsnowflake

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marcinjean-minisnowflake/health.svg)

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

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k17](/packages/civicrm-civicrm-core)[bizley/quill

Quill editor implementation for Yii 2.

64133.3k5](/packages/bizley-quill)[ebanx/benjamin

Business rule provider lib for plugin implementations

18155.2k1](/packages/ebanx-benjamin)[shel/neos-colorpicker

A plugin for Neos CMS which provides a colorpicker editor

1494.4k6](/packages/shel-neos-colorpicker)

PHPackages © 2026

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