ada-u/chocoflake
Composer 安装命令:
composer require ada-u/chocoflake
包简介
64bit time based id generator
关键字:
README 文档
README
64bit ID Generator for PHP
chocoflake is an implementation of twitter Snowflake concept. This provides generating IDs based on time in a distributed environment.
Usage
Prerequisites
- PHP 8.0 or later
Installation
Command
$ composer.phar require ada-u/chocoflake:dev-master
composer.json
{
"require": {
"ada-u/chocoflake": "dev-master"
}
}
$ composer.phar install
Sample
Configuration
- 41 bit - for timestamp
- 5 bit - for region id
- 5 bit - for server id
- 12 bit - for sequence per milliseconds
- 1414334507356 - service start epoch (unix timestamp)
$config = new IdConfig(41, 5, 5, 12, 1414334507356); $service = new ChocoflakeService($config); $worker = $service->createIdWorkerOnSharedMemory(new RegionId(1), new ServerId(1)); $id = $worker->generate(); 4194439168
ID Generator
I implemented two ID generators, Redis and SharedMemory version.
SharedMemory version
Using shared memory and semaphore (as mutex) to prevent multiple processes are in the critical section at the same time.
Redis version
Using Redis atomic increment operation to count up sequence.
ID Specification
The IDs consist of four elements:
- timestamp
- region id
- server id
- sequence
You can specify any bit length to each element.
Test
$ docker-compose run php vendor/bin/phpunit
Creating chocoflake_php_run ... done
PHPUnit 9.5.6 by Sebastian Bergmann and contributors.
.... 4 / 4 (100%)
Time: 00:00.353, Memory: 6.00 MB
OK (4 tests, 4 assertions)
License
This software is released under the MIT License, see LICENSE
ada-u/chocoflake 适用场景与选型建议
ada-u/chocoflake 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 118.18k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2014 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「id」 「chocoflake」 「idgen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ada-u/chocoflake 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ada-u/chocoflake 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ada-u/chocoflake 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Phalcon Model Generator
Auto-generate dummy data with realistic relationships per Model-like config classes
Php class generator
Code generates following files in CodeIgniter 4 : models, controllers, routes.
This VCard PHP class can generate a vCard with some data. When using an iOS device it will export as a .ics file because iOS devices don't support the default .vcf files.
统计信息
- 总下载量: 118.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-15