0

I'm looking for a good practice about generating unique big IDs like Google+ or facebook has.
Existing questions was a bout generating a unique ID not an ascendant one (uniqid() was a good way to go on).
We may rely to something basically ascendant like Timestamp time() when the user signs up, or ID of the User table $id, maybe:

  • ID = time() - 123456789 + $id.
  • Or just ID of User table, like $id + 123456789
    If we add always the same constant integer, we won't get collisions.

We can't use uniqid() to generate an ascendant ID.
And to make the auto-increment step of the database more than 1 isn't enough to have a big integer in all cases. what do you suggest?

Nadjib Mami
  • 5,736
  • 9
  • 37
  • 49
  • Why do you want to have big integer? What's the point of doing this? Just curious. – Leri Jul 26 '12 at 09:22
  • you know that facebook doesn't really generate big ids...it just came to that..retroactively I saw really small ids on facebook. Just saying. – Stoia Alex Jul 26 '12 at 09:23
  • 1
    If you really want big numbers I would just use the table ID which is allways unique and add a constant number. The "problem" is that after a while (a very long while) you will get 10 digit ID's instead of 9 digits. Well, that is: if this bothers you. – Matthias Jul 26 '12 at 09:26
  • @Matthias, no that's good in any cases. – Nadjib Mami Jul 26 '12 at 09:35

1 Answers1

2

You might want to look at this answer that explains how to generate v4 UUID in PHP here or have a look at this post, that goes through 4 ways of creating unique IDs in PHP (some of them involve uniqid() though)

Community
  • 1
  • 1
Kasia Gogolek
  • 3,374
  • 4
  • 33
  • 50