An open API service indexing awesome lists of open source software.

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

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