progamesigner/snowflakes 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

progamesigner/snowflakes

Composer 安装命令:

composer require progamesigner/snowflakes

包简介

A decentralized, k-ordered UUID generator in PHP

README 文档

README

Snowflakes is a PHP and Composer package that provides:

  • A simple 128-bit id generator.
  • Methods to convert snowflakes ID into string

Snowflakes produces 128-bit and time-ordered ids. They run one on each node in infrastructure and will generate conflict-free ids on-demand without coordination.

The project is inspired by Twitter's Snowflake and Go implementation of Discord but extended to 128-bit and not compatible with Twitter's Snowflake. This library provides a basis for id generation but not a service for handing out ids nor node id coordination.

Getting Started

Installation

composer require progamesigner/snowflakes

Usage

use ProGameSigner\Snowflakes\Node;

$node = new Node($worker_id);

$some_id = $node->next()->toString();

If you are using Laravel, you can use SnowflakesServiceProvider shipped with this package. Configure worker id with config('services.snowflakes.id', $worker_id) and get snowflake with resolve('snowflakes')->next().

Format

Snowflakes ids are 128-bits wide described here from most significant to least significant bits:

  • timestamp (64-bit) - milliseconds since the epoch (Jan 1 1970)
  • node id(48-bit) - a configurable node id
  • sequence (16-bit) - usually 0, increasing when more than one request in the same millisecond and reset to 0 when clock ticks forward

System Clock Dependency

You should use NTP to keep your system clock accurate. Snowflakes holds requests when non-monotonic clock detected. To run in a mode where NTP not move the clock backwards, see http://wiki.dovecot.org/TimeMovedBackwards#Time_synchronization for tips on how to do this.

Related Projects

Maintainers

@progamesigner.

Contribute

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that I can review your changes

License

MIT © Yang Sheng Han

统计信息

  • 总下载量: 405
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固