Download the PHP package c0dec0de/snowflake-id without Composer

On this page you can find all versions of the php package c0dec0de/snowflake-id. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package snowflake-id

c0dec0de/snowflake-id

A PHP library for generating Snowflake IDs

GitHub release PHP Build Tested With PHPUnit Coverage Status PHPStan Psalm Level 1 License

📦 Installation

The recommended way to install the package is via Composer:

❄️ What is a Snowflake ID?

A Snowflake ID is a unique 64-bit integer used in distributed systems to generate sortable, collision-resistant identifiers without a central source. Originally developed by Twitter, the format has been adopted by platforms like Discord, Instagram, and Mastodon.

Each Snowflake originally consists of:

This library follows the original Snowflake structure closely but splits the 10 bits originally allocated for the machine ID into two parts, using the following layout:

This split provides finer control over deployment in multi-datacenter environments.

Benefits of Snowflakes

Usage

🧙 Let's play with Snowflakes

You can start by generating your first Snowflake ID by running this code:

Or use the method that generates and returns a Snowflake ID as a string

⚠️ Best Practice

For production use, always explicitly provide the datacenterId, workerId, and store arguments when calling Snowflake::int() or Snowflake::string().

Providing these values ensures:

By default, if you omit these arguments:

Tip: Calling these methods without arguments is perfectly fine for prototyping, testing, or learning the API — just avoid it in real-world deployments where uniqueness and reliability are critical.

✅ Generating Globally Unique Snowflake IDs in Production

To reliably generate collision-free Snowflake IDs across multiple processes, machines, and datacenters, follow these production-grade recommendations:

✅ With this setup, your Snowflake ID generation is fully production-ready — scalable, reliable, and globally unique.

Setup Steps

  1. Configure your workerId and datacenterId. For example, assign a unique workerId to each machine within the same datacenterId.
  2. Instantiate RedisStore, passing in a properly configured Redis client (phpredis or predis/predis).

This approach guarantees safe, scalable ID generation across distributed environments.

This is the gold standard configuration for using the library to generate Snowflake IDs, guaranteeing zero collisions out of the box without any additional setup.

Customization

This library is designed for flexibility and extensibility. You can provide your own implementations of several core components.

Sequence Stores

The library includes the following built-in sequence stores:

To support other Redis clients or wrappers, you can implement your own adapter by extending the RedisConnectionAdapterInterface.

Both InMemoryStore and RedisStore implements the StoreInterface. You can create your own custom stores by implementing this interface.

ID Structure

The library comes with a standard Snowflake structure implementation:

StdStructure implements the StructureInterface. You can create your own custom structure by implementing this interface.

Sequence Generators

Available sequence generation strategies:

All sequence generators implement the SequenceGeneratorInterface, allowing you to define and plug in your own strategy if needed.

⚠️ Note:
By default (if not explicitly configured), the library uses an InMemoryStore during the ID generation process.
This store is not thread-safe and may lead to ID collisions in multi-process or concurrent environments,
as tick-sequence data remains isolated within the current process's memory and is not synchronized across processes.

For production use, consider configuring a persistent and thread-safe RedisStore.

Versioning

This library follows Semantic Versioning.

See CHANGELOG.md for release history.

Contributing

Pull requests are welcome. Please see CONTRIBUTING.md for details and code style guidelines.

License

MIT. See LICENSE file for details.

Credits

Inspired by Twitter(X)'s Snowflake algorithm.


All versions of snowflake-id with dependencies

PHP Build Version
Package Version
Requires php-64bit Version >=8.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package c0dec0de/snowflake-id contains the following files

Loading the files please wait ...