PECL UUID package : what purpose does it serve?
What purpose does the PECL UUID package serve?
It does not have any documentation. I开发者_运维技巧f we pass a name (string) can we get UUIDs; if we pass UUIDs, it will it return topic names. Are there any APIs for this purpose?
Is there any alternative for creating UUIDs?
You might want to try one of these pure code implementations for the generation of Universally Unique Identifiers (UUIDs):
http://www.ajaxray.com/blog/2008/02/06/php-uuid-generator-function/ http://www.shapeshifter.se/2008/09/29/uuid-generator-for-php/
I'm not sure why you'd pass in a string into a UUID generator - and you certainly wouldn't be able to return anything useful by passing in a UUID. The ID simply serves as something that should be globally unique once generated, and can be used for those purposes where an identifier that conforms to that principle would be useful.
The PECL extension uuid exports the function uuid_create()
which is used like in the following script:
<?php
$new_uuid = uuid_create();
echo "UUID: ", $new_uuid, "\n";
?>
I don't know of further uses, but this module contains more than this function. Sadly, it is completely undocumented. You should instead read the documentation of libuuid
, which is part of the ext2utils
project.
Some PHP alternatives can be found, like, e.g.:
- Create a GUID in PHP¹ (Windows-specific solution),
- Using the file
/proc/sys/kernel/random/uuid
in the Linux process file system (Linux-specific solution):
<?php
$fh = fopen("file:///proc/sys/kernel/random/uuid", "r");
$uuid = rtrim(fgets($fh));
fclose ($fh);
echo "UUID: {$uuid}\n";
?>
¹ The terms GUID and UUID nearly mean the same.
精彩评论