Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sschiau/Particle
64 bit ID Generator
https://github.com/sschiau/Particle
ids miliseconds php
Last synced: 2 months ago
JSON representation
64 bit ID Generator
- Host: GitHub
- URL: https://github.com/sschiau/Particle
- Owner: sschiau
- License: mit
- Created: 2013-03-27T17:34:40.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-02-16T18:33:36.000Z (almost 3 years ago)
- Last Synced: 2024-07-24T13:57:07.221Z (6 months ago)
- Topics: ids, miliseconds, php
- Language: PHP
- Homepage:
- Size: 84 KB
- Stars: 133
- Watchers: 7
- Forks: 28
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- php-awesome - Particle - 唯一 ID 生成器 (类库 / 未归类)
README
[![Build Status](https://travis-ci.org/sschiau/Particle.svg?branch=master)](https://travis-ci.org/sschiau/Particle)
[![Latest Stable Version](https://poser.pugx.org/sschiau/particle/v/stable)](https://packagist.org/packages/sschiau/particle)
[![License](https://poser.pugx.org/sschiau/particle/license)](https://packagist.org/packages/sschiau/particle)# Particle
#### Language: PHP
#### 64bits int Time Based ID Generator### Uncoordinated
For high availability within and across data centers, machines generating ids should not have to coordinate with each other.### Solution
* PHP (tested on v7.1.8)
* Particle Id (64 bits) is composed of:
* time - 42 bits (millisecond precision w/ a custom epoch)
* configured machine id - 10 bits - up to 1024 machines
* sequence number - 12 bits - up to 4096 random numbers### System Clock Dependency
You should use NTP to keep your system clock accurate.## How to use it
#### Generate Particle ID
Change const EPOCH in particle class to today epoch time w/ millisecond (13 digits)```PHP
$machineID = 0; // Machine ID (aka Server ID no.)
Particle::generateParticle($machineID);
```#### Time from Particle ID (w/ millisecond precision)
```PHP
$particleID = '4611692470816737853';
Particle::timeFromParticle($particleID);
```