Here's a simple class illustrating the proper usage (note that if php5-uuid is not installed on your system, each function call will just return false):Įcho "V3 UUID of URL='abc': ". this is the value that is to be hashed (MD5 for v3, SHA-1 for v5) it may be any string or even null The fourth argument to uuid_make() is: $url this is a secondary resource created with uuid_create() it is apparently used to generate an internal UUID, which is used as the namespace of the output UUID The third argument to uuid_make() is: $namespace The first two arguments have been demonstrated below and are straightforward, so I'll skip to the as-yet non-described arguments. The uuid_make() function takes two arguments when generating v1 or v4, but four arguments are required when generating v3 or v5. The php5-uuid functions could definitely use some documentation to clarify how they should be used, but here's what I've gleaned by examining the OSSP source code (found here: ). UUIDs generated below validates using OSSP UUID Tool, and output for named-based UUIDs are exactly the same. Given the same namespace and name, the output is always the same. They require a namespace (another valid UUID) and a value (the name). The following class generates VALID RFC 4211 COMPLIANT Universally Unique IDentifiers (UUID) version 3, 4 and 5. Here's an example of why:Īs you can see, using it w/ a DB can cause the creation of documents with repeated ID's. Databases aren't obsolete just because your app can get away with storing some info in a flat text file.Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search If you personally don't need that standard, then it's not useful for you, and never has been. There's a reason why UUIDs are a standard, and what that standard isn't "slam 16 random bytes together and go home". So sure, it'd be accurate to say "in many cases you can just do bin2hex(random_bytes(16)) to get a kinda UUID-ish string instead of generating a proper v4 UUID". (Although if so, I think you may want to rethink some bits of your design!) And as a bonus, maybe those extra 6 bits of entropy are somehow critical to your application. One common type is v4, which is, yes, 16 bytes long and has 122 bits of entropy, and yes, you could easily replace that with 16 bytes of randomness if you have no particular desire to follow a standard, interact with systems that are expecting actual v4 UUIDs, include any sort of versioning info, and have no need for some of the niceties (type hinting, etc.) that a good UUID library provides. There are several different types of UUIDs.
0 Comments
Leave a Reply. |