定制 gendoria/cruftflake 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

gendoria/cruftflake

Composer 安装命令:

composer require gendoria/cruftflake

包简介

Unique ID generator based on Twitter Snowflake, but in PHP with a simple ZeroMQ interface.

关键字:

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage Downloads Latest Stable Version

Unique ID generator based on Twitter Snowflake, but in PHP with a simple ZeroMQ interface (rather than Thrift).

This is a rewrite of dvomedia/cruftflake. It organizes the code in modules and adds several interfaces, allowing easier extension of other server and configuration mechanisms.

Implementation

The implementation copies Twitter - generating 64 bit IDs.

  • time - 41 bits
  • configured machine ID - 10 bits
  • sequence number - 12 bits

Has a custom epoch that means it can generate IDs until 2081-09-06 (not the same epoch as Snowflake).

ZooKeeper for config coordination

We use ZooKeeper to store which machine IDs are in use. When a new node starts up for the first time it must be able to contact the ZooKeeper cluster and create a new node. It will look at all the existing nodes and then (if it can't find its own Mac Address) attempt to claim a free one.

I was using Ephemeral nodes for this - similar(ish) to a lock pattern but this had the issue that the node needed to remain connected to ZK throughout its lifetime -- this way it doesn't.

The downside is that potentially the 1024 possible machine IDs will "fill up" and need to be manually pruned.

Running

Installation via composer:

	{
    	"require": {
	        "gendoria/cruftflake": "*"
		}
	}

There are several example scripts provided for playing about with. Both require previous composer update.

  1. The generator (the server)

        ./examples/server.php
  2. A client, that will generate N IDs and dump to STDOUT

    ./examples/client.php -n 100
  3. A client, that will ask server for generator status

    ./examples/status.php

For client examples to work, server example has to be be running.

Dependencies

  • ZeroMQ
  • ZooKeeper (if you want to use ZooKeeper centralized configuration)
  • Doctrine DBAL >= 2.3.0 (if you want Doctrine DBAL centralized configuration)

Composer requires php-zmq module installed.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 22
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固