note 88434 added to function.uniqid
| From: | MariusKarthaus at osu1 dot php dot net | Date: | Fri, 23 Jan 2009 19:10:47 +0000 |
| Subject: | note 88434 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149714@lists.php.net to get a copy of this message | ||
Better yet, just use the php5-uuid extension and this class to create 'official' UUIDs at
high speed (On my system 1000 UUIDs are created in 0.0064 seconds)
<?php
Usage:
$uuid=new uuid();
echo $uuid->v1();
class uuid {
/**
* This class enables you to get real uuids using the OSSP library.
* Note you need php-uuid installed.
* On my system 1000 UUIDs are created in 0.0064 seconds.
*
* @author Marius Karthaus
*
*/
protected $uuidobject;
/**
* On long running deamons i've seen a lost resource. This checks the resource and creates it
if needed.
*
*/
protected function create() {
if (! is_resource ( $this->uuidobject )) {
uuid_create ( &$this->uuidobject );
}
}
/**
* Return a type 1 (MAC address and time based) uuid
*
* @return String
*/
public function v1() {
$this->create ();
uuid_make ( $this->uuidobject, UUID_MAKE_V1 );
uuid_export ( $this->uuidobject, UUID_FMT_STR, &$uuidstring );
return trim ( $uuidstring );
}
/**
* Return a type 4 (random) uuid
*
* @return String
*/
public function v4() {
$this->create ();
uuid_make ( $this->uuidobject, UUID_MAKE_V4 );
uuid_export ( $this->uuidobject, UUID_FMT_STR, &$uuidstring );
return trim ( $uuidstring );
}
/**
* Return a type 5 (SHA-1 hash) uuid
*
* @return String
*/
public function v5() {
$this->create ();
uuid_make ( $this->uuidobject, UUID_MAKE_V5 );
uuid_export ( $this->uuidobject, UUID_FMT_STR, &$uuidstring );
return trim ( $uuidstring );
}
}
----
Server IP: 83.137.20.135
Probable Submitter: 85.147.192.41
----
Manual Page -- http://www.php.net/manual/en/function.uniqid.php
Edit -- https://master.php.net/note/edit/88434
Del: integrated -- https://master.php.net/note/delete/88434/integrated
Del: useless -- https://master.php.net/note/delete/88434/useless
Del: bad code -- https://master.php.net/note/delete/88434/bad+code
Del: spam -- https://master.php.net/note/delete/88434/spam
Del: non-english -- https://master.php.net/note/delete/88434/non-english
Del: in docs -- https://master.php.net/note/delete/88434/in+docs
Del: other reasons-- https://master.php.net/note/delete/88434
Reject -- https://master.php.net/note/reject/88434
Search -- https://master.php.net/manage/user-notes.php