https://github.com/phrenotype/munix
A unique id (64-bit integer) generator for php
https://github.com/phrenotype/munix
php php-unique-id snowflake unique-id
Last synced: 28 days ago
JSON representation
A unique id (64-bit integer) generator for php
- Host: GitHub
- URL: https://github.com/phrenotype/munix
- Owner: phrenotype
- License: mit
- Created: 2022-08-30T07:54:48.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-28T01:30:44.000Z (over 2 years ago)
- Last Synced: 2025-07-30T02:49:24.002Z (11 months ago)
- Topics: php, php-unique-id, snowflake, unique-id
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Munix : A Unique ID Generator
A unique random id generator that produces unique signed 64 bit integers without the need for a dedicated id server. The generated id's can be used as unique identifiers for objects. Collisions are guaranteed not to occur. This was built to run on one or several machines that accept multiple requests per second.
# Install
`composer install munix/munix`
# Requirements
Munix requires `sqlite` to be installed and enabled in `php.ini`. A small sqlite db it used to track number sequences within milliseconds of each other to prevent collisions. Yes, it's small. It just contains one table, one column, and one row (1 x 1).
# Usage
To get an id, you only need to call one method, `Munix\Munix::nextId(int $customId)`.
The only thing needed is a custom number from 0 (inclusive) to 1023 (inclusive). For a single project, any number in that range will suffice. However, if it's a distributed system, each machine will need a different number, to avoid collisions.
If no `custom id` is supplied, the default value of `0` is used.
```php