jwzk
asked on
PHP UNIQUE ID's / UUID
What's the best way to generate a UUID in PHP? Should it be pseudo random? or time based?
The ID's will be used with mysql as a primary key. There will be a lot of inserts/updates on the table, as well as joins.
The ID will also be used as a temporary session ID (e.g. passed in the URL), so auto increment would not be suitable.
The ID's will be used with mysql as a primary key. There will be a lot of inserts/updates on the table, as well as joins.
The ID will also be used as a temporary session ID (e.g. passed in the URL), so auto increment would not be suitable.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Would you say this type of ID would be better suited than say an actual UUID? Also, performance wise, this database will end up with 20m+ rows.
My solution generates numbers, so you can make the numbers as large as you want (within the constraints of MySQL), and numbers tend to be easier to work with. If this will be a primary key, it will be much easier to deal with than a string of letters and hyphens.
I don't know for sure, but I suspect indexing (as is always done for keys) will be quicker using integers than for complex strings.
Just make the maximum number about 5 orders of magnitude larger than the number of them that you expect to use.
I don't know for sure, but I suspect indexing (as is always done for keys) will be quicker using integers than for complex strings.
Just make the maximum number about 5 orders of magnitude larger than the number of them that you expect to use.
https://www.experts-exchange.com/questions/25016779/Good-way-of-generating-guaranteed-unique-ids.html