Download the PHP package erikwang2013/snowflake-php without Composer

On this page you can find all versions of the php package erikwang2013/snowflake-php. 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-php

Snowflake PHP

A distributed unique ID generator based on Twitter's Snowflake algorithm, compatible with Laravel, Webman, ThinkPHP, and Hyperf.

中文文档请参阅 README.zh-CN.md

About

Snowflake PHP generates 64-bit, k-ordered, globally unique IDs without requiring a central coordinator. Each ID is composed of a timestamp, datacenter ID, worker ID, and sequence number — allowing tens of thousands of IDs per second per node with no database round-trips.

Key features:

Requirements

Installation

Quick Start

With custom worker and datacenter IDs:

Configuration Reference

Key Type Default Description
epoch int 1704067200000 Custom epoch in ms (default: 2024-01-01 UTC)
worker_id int 0 Worker/node identifier
datacenter_id int 0 Datacenter identifier
worker_bits int 5 Bits for worker ID
datacenter_bits int 5 Bits for datacenter ID
sequence_bits int 12 Bits for sequence number
sequence_resolver string SequentialSequenceResolver FQCN of SequenceResolver
clock_tolerance_ms int 0 Max backward clock drift (0 = strict)

Bit Layout

Default layout (63 data bits + 1 sign bit = 64 bits total):

Maximum lifespan with default epoch: ~69 years (until ~2093).

Using Configuration Array

Framework Integration

Laravel

The package supports Laravel auto-discovery. After installation:

  1. Publish the config (optional):

  2. Configure environment variables in .env:

  3. Use the Facade or dependency injection:

Webman

  1. Copy the plugin config to your project:

  2. Register a singleton in process.php or bootstrap:

  3. Usage:

ThinkPHP 6+

  1. Copy the config file to your project:

  2. Register the service in app/service.php:

  3. Usage:

Hyperf

  1. Publish the config:

  2. Register the DI binding in config/autoload/dependencies.php:

  3. Usage via constructor injection:

ID Parsing

Decompose a Snowflake ID into its components:

Sequence Resolvers

Two built-in implementations:

SequentialSequenceResolver (default)

Classic Snowflake behavior. Sequence starts at 0 each millisecond and increments sequentially. Guarantees monotonically increasing IDs within a single node.

RandomSequenceResolver

Starts each millisecond with a random sequence number. Makes IDs less predictable (prevents enumeration) but IDs within the same millisecond are not monotonic.

Custom Resolver

Implement Snowflake\Contracts\SequenceResolver:

Exception Handling

Exception When
InvalidWorkerIdException Worker ID exceeds 2^worker_bits - 1
InvalidDatacenterIdException Datacenter ID exceeds 2^datacenter_bits - 1
ClockDriftException System clock moved backwards beyond tolerance
TimestampOverflowException Epoch has been exhausted (lifespan ended)
SnowflakeException Base exception for all package exceptions

Distributed Deployment

When running across multiple servers or processes, ensure each instance uses a unique (datacenter_id, worker_id) pair:

With the default 5+5 bit layout, you can support up to 32 datacenters × 32 workers = 1024 unique nodes.

To support more workers, adjust bit allocation:

Performance

Typical throughput on modern hardware: ~500,000 IDs/second (single process).

IDs are generated purely in-process with no external dependencies. The primary bottleneck is PHP's microtime() call and integer bit operations, both of which are O(1).

开源不易,欢迎支持

微信 支付宝

License

MIT — Copyright (c) 2026 erik https://erik.xyz


All versions of snowflake-php with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
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 erikwang2013/snowflake-php contains the following files

Loading the files please wait ...