> On Mar 16, 2020, at 11:06, Aran Reeks <cdtre...@gmail.com> wrote: > > Hi Internals, > > I'd like to open up a discussion around the implementation of a new > function within PHP for generating a UUID. > > Whilst there are libraries out there already for PHP which can generate a > UUID, all of those libraries have the possibility to generate IDs that > *could* have a collision. > > The specification for UUID versions 1 and 2 allow for collision-free ID > generation by incorporating the unique MAC addresses from network cards - > something which can't be accessed from PHP code at present. > > I can see two possible methods to enable this; > > - New function added to PHP which exposes the MAC address (allowing > external implementations for UUIDs, as well as other possible purposes a > MAC address could be used). > > - A new PHP function which introduced a uuid() function which will > generate and return version-compliant UUIDs. > > - Both of the above. > > Thoughts and feedback welcome to kickstart conversations and if there's a > positive consensus, I'd like to put forward an RFC for this to be > introduced in PHP 8. >
While undocumented, PHP has the method `net_get_interfaces()` (since PHP 7.3.0). It uses `getifaddrs()` on Linux and `GetAdaptersAddresses()` on Windows to create an array of network interface addresses. See https://github.com/php/php-src/commit/7ca5a7d84ebdc1b97f49cb460f200db093b96d9d Right now, the address is only added when it is an IPv4 or IPv6 address. It just needs to be modified to look for the correct “family” and set that as the “mac” array value for the interface. I’m currently working on a patch for this, so this might help with one aspect of your proposal. Cheers, Ben
signature.asc
Description: Message signed with OpenPGP