RE: [PHP] GUID or any other unique IDs

2005-10-26 Thread Denis Gerasimov
Hello Ben,

> While not ideal, you could do a select on a db. MS SQL and MySQL both have
> functions to generate unique id's and I imagine the other databases do as
> well. While running a "SELECT uuid()" and hitting the database for each
> one of these things is annoying, it is one possible pseudo-solution.

Finally I have come to the same solution since the generated UUIDs/GUIDs are
intended to be saved into a DB after performing some actions.

I was also suggested to use a PECL extension for this but I have no idea how
to make it work under Win32 (since it uses *nix's libuuid).

Many thanks to all contributors!

Have a great day,

Denis S Gerasimov 
Web Developer
Team Force LLC

Web:   www.team-force.org
RU & Int'l:   +7 8362-468693
email:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] GUID or any other unique IDs

2005-10-25 Thread Jasper Bryant-Greene
On Tue, 2005-10-25 at 14:47 +0400, Denis Gerasimov wrote:
> > $unique_id = sha1( uniqid( mt_rand(), true ) );
> > 
> > which should be very unique and suitable for most purposes.
> 
> I really need millions of unique IDs - hashing is not suitable for this task
> (I think so) :-(. Any more ideas?

The above function could generate much more than millions of unique IDs.

You have 1.46 x 10^48 possible hashes, and with an input of the current
time in microseconds prefixed by a Mersenne Twister random number and
suffixed by additional entropy from the combined linear congruential
generator, collisions should be *very* improbable, even when generating
IDs on multiple hosts all at the same time.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] GUID or any other unique IDs

2005-10-25 Thread Richard Lynch
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] GUID or any other unique IDs

2005-10-25 Thread Ben Litton
While not ideal, you could do a select on a db. MS SQL and MySQL both have  
functions to generate unique id's and I imagine the other databases do as  
well. While running a "SELECT uuid()" and hitting the database for each  
one of these things is annoying, it is one possible pseudo-solution.


On Tue, 25 Oct 2005 06:47:26 -0400, "Denis Gerasimov"  
<[EMAIL PROTECTED]> wrote:



Hello Jasper,


$unique_id = sha1( uniqid( mt_rand(), true ) );

which should be very unique and suitable for most purposes.


I really need millions of unique IDs - hashing is not suitable for this  
task

(I think so) :-(. Any more ideas?

Is there a PHP extension or an external library for generating GUIDs?

Have a great day,

Denis S Gerasimov
Web Developer
Team Force LLC

Web:   www.team-force.org
RU & Int'l:   +7 8362-468693
email:[EMAIL PROTECTED]




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] GUID or any other unique IDs

2005-10-25 Thread Denis Gerasimov
Hello Jasper,

> $unique_id = sha1( uniqid( mt_rand(), true ) );
> 
> which should be very unique and suitable for most purposes.

I really need millions of unique IDs - hashing is not suitable for this task
(I think so) :-(. Any more ideas?

Is there a PHP extension or an external library for generating GUIDs?

Have a great day,

Denis S Gerasimov 
Web Developer
Team Force LLC

Web:   www.team-force.org
RU & Int'l:   +7 8362-468693
email:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] GUID or any other unique IDs

2005-10-25 Thread Jasper Bryant-Greene
On Tue, 2005-10-25 at 13:01 +0400, 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.
> 
> I looked at http://pear.php.net   and
> http://pecl.php.net   but found nothing suitable
> there.
> 
> I really need "true" unique identifiers - md5() hash is not OK because of
> the "birthday paradox".
>  
> Can anyone recommend a way for solving this trouble?

I use:

$unique_id = sha1( uniqid( mt_rand(), true ) );

which should be very unique and suitable for most purposes.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] GUID or any other unique IDs

2005-10-25 Thread Richard Davey
Hi Denis,

Tuesday, October 25, 2005, 10:01:48 AM, you wrote:

> I am in a need of GUID generator but it seems that PHP doesn't have
> this as a built-in feature.

uniqid() ?

Bearing in mind of course that no unique ID generator can ever be 100%
unique unless it keeps a record of previously generated IDs. So you
may wish to add this check.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.launchcode.co.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php