Re:2^120 Ways to Ensure Unique Identifiers
by nodesocket on Wednesday February 11, 2015 @09:42PM
(#9037072)
We generate ids using the following:
`uniqid()` ensures each id is unique (somewhat), and the random paddings of 5 and 3 characters make the ids harder to guess and unpredictable.
[ Parent
| on HN ]
Re:2^120 Ways to Ensure Unique Identifiers
by stormbrew on Wednesday February 11, 2015 @09:55PM
(#9037111)
This uniqid() [1]? That appears to just be a microsecond timestamp. Definitely not globally unique by any stretch.
Yes, if you need unique, and generated on the server (not remotely) then also include getmypid() and the IP address (or name) of the webserver (if you have more than one).
Then use the option for more entropy in case the function is called more than one in a milliseconds.
So in total:
uniqid(gethostname().getmypid(), true);
Will be unique if you give sane names to your machines.