helicon-os/uuid
Composer 安装命令:
composer require helicon-os/uuid
包简介
Generic basic UUID Generator for PHP with various output formats like 16byte binary, hex formats (compact, grouped, ...), base32-like and base64-like. V4 Random UUIDs and Sequential UUIDs can be generated.
关键字:
README 文档
README
Copyright (c) 2015, Andreas Prucha, Helicon Software Development All rights reserved.
Overview
Provides basic functions to generate UUIDs on the client side. UUIDs can be generated in following formats:
- 16 byte Binary string: Big-Endian binary representation of an uuid
- 32 byte hex string: 32 chacter hex representation without dashes. The default in this library.
- 36 byte hex string: The usual string representation of uuids.
- 38 byte hex string: String representation with braces.
- 45 byte hex string: with urn:uuid-prefix
- 22 byte Base64-like string (Experimental)
- 26 byte Base32-like string (Experimental)
The library supports the following uuid sub-versions:
- V4 Random UUIDs
- "Sequential" V4 Random UIIDs (Time/Random-Based UUIDs inspired by COMB-UUIds, but slightly different)
The default version is V4Asc (Ascending Random)
If more sophisticated functions are necessary, the famous [https://packagist.org/packages/ramsey/uuid] may be worth a try.
Pitfalls and Limitations
###Byte Order
This library assumes Network Byte Order (Big Endian) as described in the RFC 4122 in the binary string representation. Unfortunately Microsoft uses Little Endian, thus conversion to the string representation may return another result there. Additionally, On systems using little endian, the V4Asc algorithm does hot have the desired effect.
###Format
32 char hex strings are used by default which can be stored in CHAR(32) fields. Please make sure that the field uses an 8bit characterset (ASCII) and a collation with no overhead (binary or similar).
| Format (Constant) | Db Type / charset / collation | Comment |
|---|---|---|
| Util::FORMAT_BIN | BINARY(16) BINARY / BINARY | Binary |
| Util::FORMAT_HEX_SHORT | CHAR(32) ASCII / ASCII or binary | Just Hex |
| Util::FORMAT_HEX_GROUPED | CHAR(36) ASCII / ASCII or binary | Hex + Formatting characters |
| Util::FORMAT_HEX_FULL | CHAR(38) ASCII / ASCII or binary | Hex + Formatting characters |
| Util::FORMAT_URN | CHAR(45) ASCII / ASCII or binary | Hex with urn:uuid:-prefix |
| Util::FORMAT_ENC32 | CHAR(26) ASCII / ASCII or binary | Experimental Base32-like sortable encoding (numbers+lc-chars) |
| Util::FORMAT_ENC64 | CHAR(26) ASCII / ASCII or binary | Experimental Base64-like sortable encoding (numbers+alpha) |
Note about chracter set and collation:
Choosing the right db type, charset and collation can have a huge impact on performance. It's not reccommended to use UTF-8 for a UUID-Field because it's a waste of space and unicode-comparisons are usually slower. Usually the best choice is to use a binary or ASCII-collation and ASCII charset (except for FORMAT_BIN, which has to be BINARY)
- All encodings are sortable and big-endian.
- All encodings except FORMAT_BIN are Url-safe
- For all encodings except FORMAT_BIN it's reccommended to use an ASCII-Character set and a binary collation in order to increase performance
- For all encodings except FORMAT_BIN and FORMAT_ENC64 it is possible to use a case insensitive collation because the string representation are never mixed case, but it should not be done.
Another option is to use the 16byte "binary" format.
Advantage of the 36byte hex format:
- No Endian-Conflict
- Readable using the usual representation
- Easy to use in hand-written queries Disadvantage of 36byte hex format:
- Uses more space
- may be slightly slower
Example
Generating a UUID is quite simple:
$newUuid = \helicon\uuid\Util::generate(); // Generates a new in default format and version
Installation
helicon-os/uuid 适用场景与选型建议
helicon-os/uuid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「uuid」 「guid」 「RFC 4122」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 helicon-os/uuid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 helicon-os/uuid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 helicon-os/uuid 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Paramconverter, Normalizer and Form Type for Ramsey Uuid
A PHP library for generating and working with identifiers, including UUIDs, ULIDs, and Snowflakes
DrUUID RFC 4122 library for PHP
Trait to generate uuid when creating models
Provides Doctrine types for mediagone/small-uid package.
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 42
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2015-05-18