See Release Notes
Long Term Support Release
V4 UUID generator.
Copyright: | 2019 Matteo Scaramuccia <moodle@matteoscaramuccia.com> |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 144 lines (5 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
uuid:: (3 methods):
generate_uuid_via_pecl_uuid_extension()
generate_uuid_via_random_bytes()
generate()
generate_uuid_via_pecl_uuid_extension() X-Ref |
Generate a V4 UUID using PECL UUID extension. return: string|bool The UUID when PECL UUID extension is available; |
generate_uuid_via_random_bytes() X-Ref |
Generate a V4 UUID using PHP 7+ features. return: string|bool The UUID when random_bytes() function is available; |
generate() X-Ref |
Generate a V4 UUID. Unique is hard. Very hard. Attempt to use the PECL UUID function if available, and if not then revert to constructing the uuid using random_bytes or mt_rand. It is important that this token is not solely based on time as this could lead to duplicates in a clustered environment (especially on VMs due to poor time precision). UUIDs are just 128 bits long but with different supported versions (RFC 4122), mainly two: - V1: the goal is uniqueness, at the cost of anonymity since it is coupled to the host generating it, via its MAC address. - V4: the goal is randomness, at the cost of (rare) collisions. Here, the V4 type is the preferred choice. The format is: xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and Y is a random choice from 8, 9, a, or b. return: string The V4 UUID. |