Download the PHP package bmilleare/sonyflake-php without Composer

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

sonyflake-php

A faithful PHP port of Sony's Sonyflake v2 distributed unique-ID generator. Same algorithm, same defaults, same bit layout — produces byte-identical IDs to the Go reference for the same inputs.

CI Packagist PHP Version

What is Sonyflake?

Sonyflake is a Snowflake-family distributed ID generator that produces sortable 63-bit integer IDs. Its layout differs from Twitter's Snowflake to favour more machines over higher per-machine throughput, and to extend the lifetime to ~174 years:

Defaults match upstream v2: 39 bits of 10ms-resolution time, 8 bits of sequence (256 IDs per 10ms per generator), 16 bits of machine id (65 536 machines), start epoch 2025-01-01T00:00:00Z.

Install

Requires PHP ^8.2.

Quick start

Two runnable example scripts ship in examples/:

⚠️ Machine IDs under PHP-FPM

Sonyflake has no PID or entropy component — uniqueness across processes rides entirely on each generator using a distinct 16-bit machine id. The Go-parity default (PrivateIpResolver, lower 16 bits of the host's private IPv4) gives every PHP-FPM worker on the same host the same id and will collide.

Under FPM (or any setup with multiple worker processes per host), use the shipped LeasedResolver with FileLeaseStore:

Each worker leases a distinct slot at boot, holds it for its lifetime (default TTL 1 hour, plus a live-PID check), and releases on exit via a shutdown hook.

Resolvers

Resolver Use when
PrivateIpResolver (implicit default) One generator per host. Not safe for FPM.
EnvResolver Orchestrator assigns each container/worker an env var (SONYFLAKE_MACHINE_ID).
LeasedResolver + FileLeaseStore Multiple workers per host (PHP-FPM, Octane, queue workers).

You can implement your own LeaseStore — Redis, APCu, etcd — by providing the three-method interface (acquire, renew, release):

Configuration

Exceptions

All exceptions implement Bmilleare\Sonyflake\Exception\SonyflakeException:

Class When
InvalidSettingsException Bad bit widths, time unit, or start time in the future.
InvalidMachineIdException Resolved machine id is out of range or rejected by checkMachineId.
OverTimeLimitException Time bits exhausted (default config: ~174 years from start).
NoPrivateAddressException PrivateIpResolver found no private IPv4.
MachineIdExhaustedException Every lease slot is held by a live worker.

Go-parity notes

Upstream parity verification

Parity isn't just claimed — it's tested against real IDs produced by the Go upstream. tests/Parity/upstream/main.go is a small program that imports github.com/sony/sonyflake/v2, runs NextID() across five configurations (default 8/16 layout, custom 4/8 layout, wider 8/20 layout, alternate machine ids, and a 1 ms time unit), and writes each id together with upstream's Decompose() output to a JSON fixture at tests/Parity/upstream-vectors.json.

UpstreamParityTest.php loads that fixture and asserts the PHP port's Sonyflake::decompose() returns the same (time, sequence, machine) tuples upstream produced for the same ids and Settings. The fixture is checked in, so CI does not need a Go toolchain.

To regenerate against a newer Sonyflake release:

If composer test still passes after regenerating, the port is in sync with that release.

Testing your own code

Inject a Bmilleare\Sonyflake\Clock\Clock implementation that returns deterministic times and records sleeps. The package's own test suite uses exactly this pattern (tests/Support/FakeClock.php).

License

MIT. See LICENSE.

Credits

Faithful port of sony/sonyflake v2 by Sony Group Corporation.


All versions of sonyflake-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
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 bmilleare/sonyflake-php contains the following files

Loading the files please wait ...