ifullgaz/laravel-global-unique-id
Composer 安装命令:
composer require ifullgaz/laravel-global-unique-id
包简介
Assign globaly unique ids to models
README 文档
README
Trait to generate 64 bit globally unique ids for all running PHP processes. The unique ID is a 64-bits integer number. Ids are guaranteed to be time ordered. The content of the integer is as follows, for example:
63 62 ------------------------------------------ 21 20 ------------ 9 8 ---------- 0
0 42 bits time in milliseonds 12 bits 9 bits
140 years until rollover to 0 unique machine id local counter
Note: bit 63 must be 0 since PHP doesn't support unsigned integers.
In this example, each PHP process can create up to 512 new ids per millisecond before any collision occurs. A total of 2,097,152 new ids could be created per milliseconds in this system.
Note: JS cannot process integers larger than 2^53-1 at this time. A good compromise is to use 42-6-5 bits as values, allowing for 64 * 32 = 2048 new ids per milliseconds. In case this is not appropriate (not enough ids/sec), the following snippet may be used to parse the raw response before deserialization:
function (data) {
data = data.replace(/:\s*(-?\d+),/g, (match, $1) => {
if ($1 <= Number.MAX_SAFE_INTEGER) {
return match;
}
return ':"'+$1+'",';
});
return data;
}
Requirements
This package requires Laravel 9 and above, apcu and redis php extensions and a redis server.
Installation
Require this package with composer.
composer require ifullgaz/laravel-global-unique-id
Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
Laravel without auto-discovery:
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
Ifullgaz\GlobalUniqueId\ServiceProvider::class,
Copy the package config to your local config with the publish command:
php artisan vendor:publish --tag=globaluniqueid-config
Options
The following options may be configured in the the globaluniqueid.php file:
/*
|--------------------------------------------------------------------------
| Start date
|--------------------------------------------------------------------------
|
| Starting reference date. Should be before today.
|
*/
'start_date' => env('GLOBAL_UNIQUE_ID_START_DATE', '01/01/2022'),
/*
|--------------------------------------------------------------------------
| Timestamp size
|--------------------------------------------------------------------------
|
| Number of bits to use for the timestamp.
| The more bits used, the larger the date range
| eg: 42 bits -> ~140 years, 41 bits -> ~70 years...
|
*/
'timestamp_size' => env('GLOBAL_UNIQUE_ID_TIMESTAMP_SIZE', 42),
/*
|--------------------------------------------------------------------------
| Machine id size
|--------------------------------------------------------------------------
|
| Number of bits to use for the machine id.
| The more bits used, the more PHP processes can run concurrently.
| eg: 11 bits -> 2^11 (2048) concurrent processes
|
*/
'machine_id_size' => env('GLOBAL_UNIQUE_ID_MACHINE_ID_SIZE', 11),
/*
|--------------------------------------------------------------------------
| Counter size
|--------------------------------------------------------------------------
|
| Number of bits to use for the local counter.
| The more bits used, the higher the local counter can go.
| eg: 10 bits -> 2^10 (1024) values
|
*/
'counter_size' => env('GLOBAL_UNIQUE_ID_COUNTER_SIZE', 10),
Usage
Add the trait to a class that has a numerical primary key as such:
use Ifullgaz\GlobalUniqueId\Models\Traits\GlobalUniqueId; class MyClass extends Model { use GlobalUniqueId; }
ifullgaz/laravel-global-unique-id 适用场景与选型建议
ifullgaz/laravel-global-unique-id 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「globalid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ifullgaz/laravel-global-unique-id 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ifullgaz/laravel-global-unique-id 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ifullgaz/laravel-global-unique-id 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Identify app models with a URI. Inspired by the globalid gem.
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-14