Download the PHP package phossa2/uuid without Composer
On this page you can find all versions of the php package phossa2/uuid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package uuid
Short Description A PHP lib to generate sequential/time based uuid for using as PK in DB.
License MIT
Homepage https://github.com/phossa2/uuid
Informations about the package uuid
phossa2/uuid
phossa2/uuid is a PHP library for generating sequential UUID to be used as primary key in databases.
It requires PHP 5.4, supports PHP 7.0+ and HHVM. It is compliant with PSR-1, PSR-2, PSR-3, PSR-4, and the proposed PSR-5.
Installation
Install via the composer
utility.
or add the following lines to your composer.json
Features
-
According to article Store UUID in an optimized way, Non-ordered UUID has big impact on Mysql db insert performance.
-
Instead of following RFC 4122 for generating UUID, we adopted a new design with data types built in. For example, user id has the type of
1010
. And any user id using this lib will start with '2101-0' -
With sharding bits built-in, it is easy to shard your db tables.
-
As long as the timestamp algorithm is good enough, it will guarantee uniqueness at least inside one vendor's house.
Design
Using 32 chars, without -
-
version: position 0, 1 char
-
this uuid lib version
- default to
2
-
-
data type: position 1 - 4, 4 chars
-
16bit, 65535
-
lib reserves types
1***
- custom types starts from
[2-f]***
-
-
timestamp: position 5 - 19, 15 chars
-
60bit
- can be used for at least 360 years
-
-
shard: position 20 - 23, 4 chars
-
16bit, 65535
- for sharding purpose, provided by user
-
-
vendor: position 24 - 27 (4 chars)
- vendor id provided by user
-
remain: position 28 - 31 (4 chars)
- reserved for future usage
Usage
Extend Phossa2\Uuid\Uuid
with your own settings or algorithm,
APIs
-
Uuid::get(string $dataType, string $shardId): string
Both parameters are optional.
-
Uuid::isValid(string $uuid): bool
Check
$uuid
valid or not.Uuid::info(string $uuid): array
Get detail information about this
$uuid
includingversion
,type
,time
,vendor
,remain
.Uuid::encode(string $uuid): string
Encode
$uuid
into a short version (base56)Uuid::decode(string $string): string
Decode the short version into full 32-char UUID
Predefined data types
-
Generic OID
UuidInterface::TYPE_OID
, value1000
. -
User id
UuidInterface::TYPE_USER
, value1010
. -
Post or article
UuidInterface::TYPE_POST
, value1020
. -
News
UuidInterface::TYPE_NEWS
, value1021
. -
Image
UuidInterface::TYPE_IMAGE
, value1030
. -
Image album
UuidInterface::TYPE_ALBUM
, value1031
. -
Comment
UuidInterface::TYPE_COMM
, value1040
. - Rating
UuidInterface::TYPE_RATE
, value1041
.
Change log
Please see CHANGELOG from more information.
Testing
Contributing
Please see CONTRIBUTE for more information.
Dependencies
-
PHP >= 5.4.0
- phossa2/shared >= 2.0.21