...

View Full Version : php5 uuid



werty37
06-15-2006, 08:39 AM
Hi everyone,
Does anyone know how to use php5 uuid in php scripts?

Thanks in advance
werty

fci
06-15-2006, 01:55 PM
http://us2.php.net/uniqid ?

werty37
06-16-2006, 03:14 AM
HI
I am not speaking of uniqid..
I am using ubuntu dapper. recently i was browsing thru my synaptic when
i came across a package named "php5-uuid"
The description says:

OSSP uuid module for php5
OSSP uuid is an ISO-C and Perl application programming interface (API)
and corresponding command line interface (CLI) for the generation of
DCE 1.1 and ISO/IEC 11578:1996 compliant Universally Unique Identifier
(UUID). It supports DCE 1.1 variant UUIDs of version 1 (time and node
based), version 3 (name based) and version 4 (random number based).

UUIDs are 128 bit numbers which are intended to have a high likelihood
of uniqueness over space and time and are computationally difficult
to guess. They are globally unique identifiers which can be locally
generated without contacting a global registration authority. UUIDs
are intended as unique identifiers for both mass tagging objects
with an extremely short lifetime and to reliably identifying very
persistent objects across a network.

This package provides a module for OSSP uuid functions support in PHP
scripts.

I want to know how to use this php scripts..

Thanks in advance

eak
06-16-2006, 05:16 AM
Official page.
http://pecl.php.net/package/uuid

Look here for some examples.
http://viewcvs.php.net/viewcvs.cgi/pecl/uuid/tests/?sortby=rev

werty37
06-16-2006, 07:46 AM
Hey thanks
I executed this code. But it always prints skip.. How do i actually
load the extension?



<?php if (!extension_loaded("uuid")) die( "skip"); ?>

<?php
// check basic format of generated UUIDs
$uuid = uuid_create();
if (ereg("[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}", $uuid)) {
echo "basic format ok\n";

echo "NULL UUID ";
$uuid = uuid_create(UUID_TYPE_NULL);
echo uuid_is_null($uuid) ? "ok\n" : "failed: $uuid\n";

echo "Time based UUID ";
$uuid = uuid_create(UUID_TYPE_TIME);
echo uuid_type($uuid) == UUID_TYPE_TIME ? "ok\n" : "failed: $uuid (".uuid_type($uuid).",".UUID_TYPE_TIME.")\n";

echo "Random UUID ";
$uuid = uuid_create(UUID_TYPE_RANDOM);
echo uuid_type($uuid) == UUID_TYPE_RANDOM ? "ok\n" : "failed: $uuid\n";

} else {
echo "basic UUID format check failed, generated UUID was $uuid\n";
}
?>

Thanks in advance

fci
06-16-2006, 01:16 PM
try http://us3.php.net/dl or putting it in your php.ini (a line that looks like "extension=uuid.so")

werty37
06-16-2006, 06:01 PM
Hi

Thanks for reply.
I was able to load the extension successfully using dl. But now there is some
parametric error. Even the scripts from php5-uuid cvs wont work.


<?php

if (!extension_loaded('uuid')) {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
echo $prefix . 'uuid.'.PHP_SHLIB_SUFFIX;
dl($prefix . 'uuid.' . PHP_SHLIB_SUFFIX);
}

// check basic format of generated UUIDs
$uuid = uuid_create();
if (ereg("[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}", $uuid)) {
echo "basic format ok\n";

echo "NULL UUID ";
$uuid = uuid_create(UUID_TYPE_NULL);
echo uuid_is_null($uuid) ? "ok\n" : "failed: $uuid\n";

echo "Time based UUID ";
$uuid = uuid_create(UUID_TYPE_TIME);
echo uuid_type($uuid) == UUID_TYPE_TIME ? "ok\n" : "failed: $uuid (".uuid_type($uuid).",".UUID_TYPE_TIME.")\n";

echo "Random UUID ";
$uuid = uuid_create(UUID_TYPE_RANDOM);
echo uuid_type($uuid) == UUID_TYPE_RANDOM ? "ok\n" : "failed: $uuid\n";

} else {
echo "basic UUID format check failed, generated UUID was $uuid\n";
}
?>

The error returned is:
Warning: uuid_create() expects exactly 1 parameter, 0 given in /var/www/test/phpuuid.php on line 10

Thanks

fci
06-16-2006, 06:18 PM
try changing line10 to uuid_create(UUID_TYPE_DEFAULT)

fci
06-16-2006, 06:20 PM
if you download uuid from here and browse some of the source code, that might help you, http://www.pecl.php.net/package/uuid

werty37
06-17-2006, 04:39 AM
HI
A new error pops:

Warning: uuid_create() [function.uuid-create]: uuid_create: parameter wasn't passed by reference in /var/www/test/phpuuid.php on line 10



.............................
..............................
echo $prefix . 'uuid.'.PHP_SHLIB_SUFFIX;
dl($prefix . 'uuid.' . PHP_SHLIB_SUFFIX);
}

// check basic format of generated UUIDs
$uuid = UUID_CREATE(UUID_TYPE_DEFAULT);

if (ereg("[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}", $uuid)) {
echo "basic format ok\n";
..................
..................



Thanks in Advance

fci
06-17-2006, 07:12 PM
try uuid_create(UUID_TYPE_NULL) or maybe uuid_create(&UUID_TYPE_DEFAULT)

werty37
06-17-2006, 07:50 PM
HI
I forgot to mention. I tried
uuid_create(UUID_TYPE_NULL)
uuid_create(UUID_TYPE_DEFAULT)
uuid_create(UUID_TYPE_DCE)
uuid_create(UUID_TYPE_RANDOM)
uuid_create(UUID_TYPE_TIME)
nothing is working....

add &...
uuid_create(&UUID_TYPE_DEFAULT)
error:
Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /var/www/test/phpuuid.php on line 11

i tried something like this
$uid = 'UUID_TYPE_DEFAULT';
echo uuid_create(&$uid);

It simply executes without any error but it does not
print any uuid.

Thanks

s2theg
10-28-2009, 10:25 PM
This thread is pretty old, but just to help others having the same issue:

Ubuntu doesn't use the pecl extension for php5-uuid they use the ossp-uuid module which is going to confuse the peace out of most php developers.

Here is a usage example of both libraries:



if(function_exists(uuid_make))
{
uuid_create(&$v1);
uuid_make($v1, UUID_MAKE_V1);
uuid_export($v1, UUID_FMT_STR, &$v1String);

uuid_create(&$v3);
uuid_make($v3, UUID_MAKE_V3);
uuid_export($v3, UUID_FMT_STR, &$v3String);

uuid_create(&$v4);
uuid_make($v4, UUID_MAKE_V4);
uuid_export($v4, UUID_FMT_STR, &$v4String);

uuid_create(&$v5);
uuid_make($v5, UUID_MAKE_V5);
uuid_export($v5, UUID_FMT_STR, &$v5String);

uuid_create(&$MC);
uuid_make($MC, UUID_MAKE_MC);
uuid_export($MC, UUID_FMT_STR, &$MCString);

echo "V1: " . $v1String .
"V3: " . $v3String . "\n" .
"V4: " . $v4String . "\n" .
"V5: " . $v5String . "\n" .
"MC " . $MCString . "\n";
}
else
{
echo "DEFAULT: " . uuid_create(UUID_TYPE_DEFAULT) . "\n" .
"TIME: " . uuid_create(UUID_TYPE_TIME) . "\n" .
"DCE: " . uuid_create(UUID_TYPE_DCE) . "\n" .
"NAME: " . uuid_create(UUID_TYPE_NAME) . "\n" .
"RANDOM: " . uuid_create(UUID_TYPE_RANDOM) . "\n";
}


Other UUID format constants:
UUID_FMT_BIN
UUID_FMT_STR
UUID_FMT_SIV
UUID_FMT_TXT

I prefer the latter ossp-uuid api, but it is my opinion that Ubuntu really should have used the upstream project at pecl instead of implementing an interface that most php developers will be unfamiliar with. Then all of this confusion could have been avoided

If Ubuntu decides to put in a php5-ossp-uuid package and build the pecl extension uuid as php5-uuid package, then that would be really awesome.:thumbsup:

Here is more on this issue:

https://answers.launchpad.net/ubuntu/+source/ossp-uuid/+question/87216
https://bugs.launchpad.net/ubuntu/+source/ossp-uuid/+bug/283398

Happy coding.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum