tuupola/ksuid
Composer 安装命令:
composer require tuupola/ksuid
包简介
K-Sortable Globally Unique IDs
关键字:
README 文档
README
This library implements the K-Sortable Globally Unique IDs from Segment. See also the article called A Brief History of the UUID.
KSUID is for K-Sortable Unique IDentifier. It's a way to generate globally unique IDs similar to RFC 4122 UUIDs, but contain a time component so they can be "roughly" sorted by time of creation. The remainder of the KSUID is randomly generated bytes.
Install
Install with composer.
$ composer require tuupola/ksuid
This branch requires PHP 7.1 or up. The older 1.x branch supports also PHP 5.6 and 7.0.
$ composer require "tuupola/ksuid:^1.0"
Usage
Included Base62 implementation has both PHP and GMP based encoders. By default encoder and decoder will use GMP functions if the extension is installed. If GMP is not available pure PHP encoder will be used instead.
Note! Throughout the code the term timestamp refers to KSUID timestamp. The term unixtime refers to the traditional Unix time. KSUID timestamp and Unix time have different Epoch.
use Tuupola\Ksuid; $ksuid = new Ksuid; print $ksuid; /* p6UEyCc8D8ecLijAI5zVwOTP3D0 */ print $ksuid->timestamp(); /* 94985761 */ print $ksuid->unixtime(); /* 1494985761 */ print bin2hex($ksuid->payload()); /* d7b6fe8cd7cff211704d8e7b9421210b */ $datetime = (new \DateTimeImmutable) ->setTimestamp($ksuid->unixtime()) ->setTimeZone(new \DateTimeZone("UTC")); print $datetime->format("Y-m-d H:i:s"); /* 2017-05-17 01:49:21 */
If you prefer static syntax you can use one of the provided factories.
use Tuupola\KsuidFactory as Ksuid; $ksuid = Ksuid::create(); $ksuid = Ksuid::fromString("0o5Fs0EELR0fUjHjbCnEtdUwQe3"); $binary = hex2bin("05a95e21d7b6fe8cd7cff211704d8e7b9421210b"); $ksuid = Ksuid::fromBytes($binary); $ksuid = Ksuid::fromTimestamp(94985761); $ksuid = Ksuid::fromUnixtime(1494985761); $timestamp = 94985761; $payload = hex2bin("d7b6fe8cd7cff211704d8e7b9421210b"); $ksuid = Ksuid::fromTimestampAndPayload($timestamp, $payload);
Testing
You can run tests either manually or automatically on every code change. Automatic tests require entr to work.
$ make test
$ brew install entr $ make watch
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email tuupola@appelsiini.net instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
tuupola/ksuid 适用场景与选型建议
tuupola/ksuid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.28M 次下载、GitHub Stars 达 108, 最近一次更新时间为 2017 年 06 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「base62」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tuupola/ksuid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tuupola/ksuid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tuupola/ksuid 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
base62 encoder and decoder also for big numbers with Laravel integration
Convert integers between arbitrary bases with custom alphabets, salt, padding, and big-integer support.
Compact, time-sortable unique ID generator for PHP. Drop-in UUID/ULID alternative with base62 encoding, Stripe-style prefixes, and configurable entropy profiles.
Convert number (string format) between base 2 and 62
Various identifier classes for ID conversion and presentation.
Base62 encoder and decoder
统计信息
- 总下载量: 1.28M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 109
- 点击次数: 32
- 依赖项目数: 4
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-08