Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: php5 uuid

  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation php5 uuid

    Hi everyone,
    Does anyone know how to use php5 uuid in php scripts?

    Thanks in advance
    werty

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation

    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

  • #4
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • #5
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Hey thanks
    I executed this code. But it always prints skip.. How do i actually
    load the extension?

    Code:
    <?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

  • #6
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try http://us3.php.net/dl or putting it in your php.ini (a line that looks like "extension=uuid.so")

  • #7
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <?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

  • #8
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try changing line10 to uuid_create(UUID_TYPE_DEFAULT)

  • #9
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you download uuid from here and browse some of the source code, that might help you, http://www.pecl.php.net/package/uuid

  • #10
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    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

    Code:
      
    .............................
    .............................. 
    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

  • #11
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try uuid_create(UUID_TYPE_NULL) or maybe uuid_create(&UUID_TYPE_DEFAULT)

  • #12
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #13
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Ubuntu UUID library

    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:

    PHP Code:
    if(function_exists(uuid_make))
    {
        
    uuid_create(&$v1);
        
    uuid_make($v1UUID_MAKE_V1);
        
    uuid_export($v1UUID_FMT_STR, &$v1String);

        
    uuid_create(&$v3);
        
    uuid_make($v3UUID_MAKE_V3);
        
    uuid_export($v3UUID_FMT_STR, &$v3String);
        
        
    uuid_create(&$v4);
        
    uuid_make($v4UUID_MAKE_V4);
        
    uuid_export($v4UUID_FMT_STR, &$v4String);
        
        
    uuid_create(&$v5);
        
    uuid_make($v5UUID_MAKE_V5);
        
    uuid_export($v5UUID_FMT_STR, &$v5String);
        
        
    uuid_create(&$MC);
        
    uuid_make($MCUUID_MAKE_MC);
        
    uuid_export($MCUUID_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.

    Here is more on this issue:

    https://answers.launchpad.net/ubuntu...question/87216
    https://bugs.launchpad.net/ubuntu/+s...id/+bug/283398

    Happy coding.


  •  

    LinkBacks (?)

    1. 09-11-2014, 09:22 AM
    2. 08-28-2014, 08:55 PM

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •