Re: GUID or any other unique IDs
| From: | Richard Lynch | Date: | Tue, 25 Oct 2005 17:53:19 +0000 |
| Subject: | Re: GUID or any other unique IDs | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-224649@lists.php.net to get a copy of this message | ||
On Tue, October 25, 2005 4:01 am, Denis Gerasimov wrote:
> I am in a need of GUID generator but it seems that PHP doesn't have
> this as
> a built-in feature.
There is some discussion here you may find useful:
http://www.php.net/uniqid
> I really need "true" unique identifiers - md5() hash is not OK because
> of
> the "birthday paradox".
If you already have a database connection you can simply use a
sequence (or auto_increment in MySQL)
But that assumes you are willing to have predictable IDs, which you
might not.
> Can anyone recommend a way for solving this trouble?
You could use md5() and track every ID you hand out in a UNIQUE column
in a db, and simply generate another random md5() if you happen to run
into a duplicate.
The probability that you'd generate too many duplicate random md5()s
in a row for performance to be an issue is pretty small, if you
already have database activity going on.
--
Like Music?
http://l-i-e.com/artists.htm