# UUID

- Thread: https://externals.io/message/92209
- Original archive: https://news-web.php.net/php.internals/92209
- Started by Sebastian Bergmann on 2016-04-12T06:09:05+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #92209 — Sebastian Bergmann — 2016-04-12T06:09:05+00:00

URL: https://externals.io/message/92209#92209

In PHP 7.0 we introduced `random_bytes()` which wraps Linux's getrandom(2)
as well as Windows's CryptGenRandom() and uses /dev/urandom as a fallback.

I think it would be great if we added a function that wraps
/proc/sys/kernel/random/uuid [2] and, if that exists, its equivalent on
Windows to make the generation of UUIDs easy.

Thoughts?

---

## #92211 — Pierre Joye — 2016-04-12T07:52:53+00:00

URL: https://externals.io/message/92209#92211 · In reply to: #92209

>
> In PHP 7.0 we introduced `random_bytes()` which wraps Linux's getrandom(2)
> as well as Windows's CryptGenRandom() and uses /dev/urandom as a fallback.
>
> I think it would be great if we added a function that wraps
> /proc/sys/kernel/random/uuid [2] and, if that exists, its equivalent on
> Windows to make the generation of UUIDs easy.
>
> Thoughts?

Alternatively and maybe more portable, libuuid (should be part of all
decent systems too) could be a first choice. BSD also provides
compliant APIs as part of their libc
(https://www.freebsd.org/cgi/man.cgi?query=uuid for freebsd f.e.). On
Windows

UuidCreate and UuidToString should do it but I did not check their
compliance yet.

For the reference here: by compliant, I mean compliant with
https://tools.ietf.org/html/rfc4122


Cheers,
Pierre

---

## #92212 — Pierre Joye — 2016-04-12T07:59:46+00:00

URL: https://externals.io/message/92209#92212 · In reply to: #92211

> 
> > […]
>
> Alternatively and maybe more portable, libuuid (should be part of all
> decent systems too) could be a first choice.

Forgot to mention: https://pecl.php.net/package/uuid

> BSD also provides
> compliant APIs as part of their libc
> (https://www.freebsd.org/cgi/man.cgi?query=uuid for freebsd f.e.). On
> Windows
>
> UuidCreate and UuidToString should do it but I did not check their
> compliance yet.
>
> For the reference here: by compliant, I mean compliant with
> https://tools.ietf.org/html/rfc4122
>
>
> Cheers,
> Pierre



-- 
Pierre

@pierrejoye | http://www.libgd.org

---

## #92213 — Leszek Krupinski — 2016-04-12T08:10:01+00:00

URL: https://externals.io/message/92209#92213 · In reply to: #92211

> On Apr 12, 2016 1:09 PM, "Sebastian Bergmann" <sebastian@php.net
> <javascript:;>> wrote:
> > […]
> fallback.
> > […]
>
> Alternatively and maybe more portable, libuuid (should be part of all
> decent systems too) could be a first choice. BSD also provides
> compliant APIs as part of their libc
> (https://www.freebsd.org/cgi/man.cgi?query=uuid for freebsd f.e.). On
> Windows
>
>

I have partially implemented bindings for libuuid into the core, I can
finish it if you will.

--Leszek

---

## #92216 — Matteo Beccati — 2016-04-12T09:13:03+00:00

URL: https://externals.io/message/92209#92216 · In reply to: #92212

Hi,


> > […]
> 
> Forgot to mention: https://pecl.php.net/package/uuid
> 
> > […]

I have worked on the addition of Linux libuuid + BSD support to Postgres
9.4 to the existing (deprecated) uuid-ossp a couple of years back. I
pretty sure we can reuse some of that investigation / code for php too.


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/

---

## #92220 — Colin O'Dell — 2016-04-12T12:56:31+00:00

URL: https://externals.io/message/92209#92220 · In reply to: #92209

On Tue, Apr 12, 2016 at 2:09 AM Sebastian Bergmann <sebastian@php.net>
wrote:

> In PHP 7.0 we introduced `random_bytes()` which wraps Linux's getrandom(2)
> as well as Windows's CryptGenRandom() and uses /dev/urandom as a fallback.
>
> I think it would be great if we added a function that wraps
> /proc/sys/kernel/random/uuid [2] and, if that exists, its equivalent on
> Windows to make the generation of UUIDs easy.
>
> Thoughts?
>

I'd love to see UUID generation in core using a similar platform-based
approach, as long as the implementation matches RFC 4122.  Part of this
will be determining which versions/variants should be supported:
https://en.wikipedia.org/wiki/Universally_unique_identifier#RFC_4122_Variant

Version 4 (random) UUIDs is an obvious choice, but should any others be
supported initially?

Perhaps the implementation could be a simple function named random_uuid()
which either takes no parameters or a single parameter "$version" which
defaults to 4?

Regards,

Colin

---

## #92225 — Pierre Joye — 2016-04-12T13:21:52+00:00

URL: https://externals.io/message/92209#92225 · In reply to: #92220

>
> On Tue, Apr 12, 2016 at 2:09 AM Sebastian Bergmann <sebastian@php.net>
> wrote:
>
> > […]
fallback.
> > […]
>
> I'd love to see UUID generation in core using a similar platform-based
> approach, as long as the implementation matches RFC 4122.  Part of this
> will be determining which versions/variants should be supported:
>
https://en.wikipedia.org/wiki/Universally_unique_identifier#RFC_4122_Variant
>
> Version 4 (random) UUIDs is an obvious choice, but should any others be
> supported initially?
>
> Perhaps the implementation could be a simple function named random_uuid()
> which either takes no parameters or a single parameter "$version" which
> defaults to 4?

I would prefer not to refer to random to avoid any confusion with the
recent added random function. As uuid is not crypto safe and is not aimed
to. Users will then hopefully not think about using instead of the random
api.

Also uuid alone may be a problem (bc?) It sounds like a logical choice.
Alternatively uuid_create ().

Cheers
Pierre

---

## #92226 — Colin O'Dell — 2016-04-12T13:30:20+00:00

URL: https://externals.io/message/92209#92226 · In reply to: #92225

>
> I would prefer not to refer to random to avoid any confusion with the
> recent added random function. As uuid is not crypto safe and is not aimed
> to. Users will then hopefully not think about using instead of the random
> api.
>
> Also uuid alone may be a problem (bc?) It sounds like a logical choice.
> Alternatively uuid_create ().
>
Ah yes, good point.  I was thinking random_uuid() might be good for v4
UUIDs, and that a parameter might be needed, but I failed to make the
connection that not all UUID versions are random - my apologies for not
catching that before hitting send.

I like the idea of uuid() or uuid($version = 4)

---

## #92227 — Remi Collet — 2016-04-12T13:40:28+00:00

URL: https://externals.io/message/92209#92227 · In reply to: #92209

Perhaps, no need to reinvent the wheel...

There is already 2 uuid extensions

- the one provided in the libuuid sources
- the pecl one : https://pecl.php.net/package/uuid

No need to create more confusion.

If something missing, just add it in the existing pecl ext.

If needed, open a RFC to merge the extension in php.


Remi.

---

## #92229 — Pierre Joye — 2016-04-12T14:16:53+00:00

URL: https://externals.io/message/92209#92229 · In reply to: #92227

> Perhaps, no need to reinvent the wheel...
>
> There is already 2 uuid extensions
>
> - the one provided in the libuuid sources
> - the pecl one : https://pecl.php.net/package/uuid
>
> No need to create more confusion.
>
> If something missing, just add it in the existing pecl ext.
>
> If needed, open a RFC to merge the extension in php.

This is why I referred to this extension and lib. However they are
only based on libuuid. We still need to support windows and I would
prefer to use libc's uuid for BSD. I think pecl's uuid could be good
start to make it more portable across system.

The API is already clear (generation and comparison, not sure we need
much more). I am not sure either about the various platforms and what
they support in term of UUID versions. We have to clarify this point
before anything can be merged.

Cheers,
-- 
Pierre

@pierrejoye | http://www.libgd.org
