The favored PHP UUID library by Ben Ramsey launched a brand new model with assist for UUID v8, customized UUIDs:
I simply printed model 4.6.0 of ramsey/uuid from #LonghornPHP!
It contains assist for model 8, customized UUIDs, and it ensures monotonicity in model 7, Unix Epoch time UUIDs.https://t.co/MkIvBsRhol
Learn extra about model 8 UUIDs right here: https://t.co/8IbHyfP9gW
Cheers!
— Ben Ramsey 🇺🇦 (@ramsey) November 6, 2022
The UUID package deal implements the UUID v8 draft spec, which outlines a couple of potentials causes one may think about using UUID v8:
- An implementation want to embed additional data inside the UUID aside from what’s outlined on this doc.
- An implementation has different software/language restrictions which inhibit the usage of one of many present UUIDs.
Here is an instance of producing a model 8 customized UUID:
1use RamseyUuidUuid;
2Â
3/*
4The bytes ought to be a 16-byte octet string, an open blob of knowledge that you could be fill with 128 bits of knowledge. Nonetheless, bits 48 by 51 shall be changed with the UUID model area, and bits 64 and 65 shall be changed with the UUID variant. You have to not depend on these bits to your software wants.
5*/
6Â
7$uuid = Uuid::uuid8("x00x11x22x33x44x55x66x77x88x99xaaxbbxccxddxeexff");
8Â
9printf(
10 "UUID: %snModel: %dn",
11 $uuid->toString(),
12 $uuid->getFields()->getVersion()
13);
14Â
15/*
16UUID: 00112233-4455-8677-8899-aabbccddeeff
17Model: 8
18*/
To be taught extra about utilizing model 8 UUIDs, learn Model 8: Customized within the ramsey/uuid Guide. You possibly can learn extra about UUID v8 draft spec if you would like extra technical particulars.
Observe: the Laravel framework v9 requires ramsey/uuid:^4.2.2
and you may replace dependencies to get the newest model of ramsey/uuid
if you would like to experiment additional: