Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Home

shadowhand edited this page · 5 revisions
Clone this wiki locally

UUID

Universally Unique Identifiers, sometimes also called Globally Unique Identifiers (GUIDs), can be used as identifiers for many objects with a short lifetime, such as cache key names, or for reliably identifying more permanent entities, such as database records across multiple, sharded database servers.

This modules should be installed to modules/uuid and enabled in bootstrap.php.

Available Methods

Random uuids are based on multiple random values. The probability of collision is low enough to be used as unique values. The UUID::v4 method is used to generate a random identifier:

$uuid = UUID::v4();

For hashing, use the UUID::v5() method to create an sha1 hashed uuid. If you prefer md5 hashing, use the UUID::v3 method. These methods will return the same uuid every time that the namespace and key are the same. Both methods take two parameters, the "namespace" and the "key name". The namespace must be the uuid of the namespace that the hash is being generated for. The uuid specifications defines the recommended namespace keys for DNS records (constant UUID::DNS), URL addresses (UUID::URL), ISO object identifiers (UUID::OID), and X.500 distinguished names (UUID::X500).

To generate a uuid for the url http://example.com/test.html using sha1:

$uuid = UUID::v5(UUID::URL, 'http://example.com/test.html');

To generate a uuid for the domain db.example.com using sha1:

$uuid = UUID::v5(UUID::DNS, 'db.example.com');

The same domain uuid generated using md5 instead of sha1:

$uuid = UUID::v3(UUID::DNS, 'db.example.com');

It is recommended to use the default namespaces when possible, but not required. Generating a custom namespace is done using the same v3 and v5 methods, but with no starting namespace:

$namespace = UUID::v5(UUID::NIL, 'my namespace');

It is not recommended to use UUID::NIL as your namespace. Only use UUID::NIL to generate the hash namespaces.

Something went wrong with that request. Please try again.