Re: unique id
| From: | Gabriel Guzman | Date: | Mon, 28 Jul 2003 18:42:09 +0000 |
| Subject: | Re: unique id | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-157221@lists.php.net to get a copy of this message | ||
On Sat, 2003-07-26 at 07:11, Curt Zirzow wrote:
> * Thus wrote jan (jan@plazma.sk):
> > Hi there!
> >
> > What's the best way to create uids (unique ids) even when runnig at
> > exactly same time (microseconds)?
> >
> > is this enough ???
> >
> > $r = mt_rand();
> > $uid = uniqid(getmypid() . $r);
>
> If you're running a cluster of machines I would include information
> on the machine that is generating the uid.
>
> $uid = uniqid(getmypid() . $r . '_MACHINE_NAME_');
>
> Curt
this is similar to what we do as well:
hexadecimal timestamp + hexadecimal pid + hexadecimal randomvalue + hex
ip address of server (only used if using multiple machines, otherwise
this part is left off).
I've also considered using semaphores in my id generation function to
insure only one counter can be created at a time, but am worried that
this might cause a bit of a performance hit. Anyone tried this?
gabe.