Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Identify All the Things With UUIDs! (AtlantaPHP May 2016)

Identify All the Things With UUIDs! (AtlantaPHP May 2016)

Universally unique identifiers (UUIDs) are a fun and exciting way to identify things. We can issue UUIDs forever and never run out; they're practically unique! Join this whirlwind adventure in search of the perfect identifier to find out why UUIDs might be good for your projects.


Ben Ramsey

May 05, 2016


  1. Identify All the Things With UUIDs Ben Ramsey AtlantaPHP 5

    May 2016
  2. What is a UUID?

  3. universally unique identifier

  4. universally unique There are 1632 possible UUIDs “only after generating

    1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%” — Wikipedia, UUID
  5. 128-bit integer 379dae82-5a2b-4c4b-8193-b8e7749a3495

  6. RFC 4122 Defines a specific variant of UUID with five

  7. composer require ramsey/uuid

  8. use Ramsey\Uuid\Uuid;

  9. Version 1: Time Based

  10. $uuid = Uuid::uuid1(); echo $uuid->toString();

  11. for ($i = 0; $i < 5; $i++) { echo

    Uuid::uuid1()->toString(); echo "\n"; }
  12. 68845efc-1303-11e6-8d40-3c15c2cafa76 68846d0c-1303-11e6-8088-3c15c2cafa76 68847216-1303-11e6-830b-3c15c2cafa76 68847590-1303-11e6-892a-3c15c2cafa76 68847806-1303-11e6-913b-3c15c2cafa76

  13. Version 2: DCE Security

  14. Version 3: Name Based MD5

  15. $atlphpNS = Uuid::uuid3( Uuid::NAMESPACE_DNS, 'atlantaphp.org' ); $pageId = Uuid::uuid3( $atlphpNS,

    'april-2016-meeting' );
  16. cee20bf0-822d-3501-8bf3-7ccd5ed5966e

  17. Version 4: Random

  18. for ($i = 0; $i < 5; $i++) { echo

    Uuid::uuid4()->toString(); echo "\n"; }
  19. 28b7883f-3df0-4e8a-9994-57b28f01fab2 dd78278c-03d7-4ca4-8411-06380c4cfd57 ae8de9f1-6ffc-454e-8522-b2c260e4c66b a5e9ac6b-0680-4fb7-a019-f305c7d2d5da 09fd4b15-2b2d-49be-af51-30899169ff99

  20. Version 5: Name Based SHA-1

  21. $atlphpNS = Uuid::uuid5( Uuid::NAMESPACE_DNS, 'atlantaphp.org' ); $pageId = Uuid::uuid5( $atlphpNS,

    'april-2016-meeting' );
  22. 6065c1e5-54d9-50f2-b9ad-3bee82277a9b

  23. Advanced

  24. $factory = new UuidFactory(); $generator = new CombGenerator( $factory->getRandomGenerator(), $factory->getNumberConverter()

    ); $codec = new TimestampFirstCombCodec( $factory->getUuidBuilder() ); $factory->setRandomGenerator($generator); $factory->setCodec($codec); Uuid::setFactory($factory); for ($i = 0; $i < 5; $i++) { echo Uuid::uuid4()->toString(); echo "\n"; }
  25. 85031b4a-26c8-4689-a4e9-8d24fcb961b9 85031b4a-26e6-42e3-82ac-efc012d82dce 85031b4a-26fb-4c3d-ba85-0c5bc8365bdd 85031b4a-270c-4a01-97f6-eeeb1bbbf70e 85031b4a-271d-4d4b-bc49-a364fc1fc9f4

  26. THANK YOU. ANY QUESTIONS? If you want to talk more,

    feel free to contact me. benramsey.com @ramsey github.com/ramsey ben@benramsey.com Identify All the Things With UUIDs Copyright © 2016 Ben Ramsey This work is licensed under Creative Commons Attribution- ShareAlike 4.0 International. For uses not covered under this license, please contact the author. Ramsey, Ben. “Identify All the Things With UUIDs.” AtlantaPHP. Insight Global, Atlanta. 5 May 2016. Conference presentation. This presentation was created using Keynote. The text is set in Chunk Five and Helvetica Neue. The source code is set in Menlo. The iconography is provided by Font Awesome. Unless otherwise noted, all photographs are used by permission under a Creative Commons license. Please refer to the Photo Credits slide for more information. bram.se/ramsey-uuid lj bram.se/atlphp-uuids
  27. PHOTO CREDITS 1. “38-365 Fingerprint” by Bram Cymet 2. “Baby

    Feet” by Katelyn Kenderdine 3. “Security door” by reynermedia 4. “Hello My Name Is.... 221/365” by Robert Occhialini 5. “Random” by Vladimer Shioshvili 6. “Hello! My Name Is JEDi.” by Tyrone J Moore 7. “Curvy Road Ahead” by Kit Ng 1 2 3 4 5 6 7