2

I read about the UUID v4 and it's virtually unique, and that's what I need. The problem is, it's a too large number, is it possible to generate UUID's like Facebook or Twitter with fewer characters?

I read some post, where you can shrink this code to 20 with Ascii85, but don't see a reliable PHP script doing the job. Someone knows a tested class?? for random ID's it the best way to store this 20 char, right?

--- Edit ---

@David Schwartz

Thanks. I need a random unique identifier in a single server, between 8 and 16 chars (ok 20 is fine if its the lowest). The idea it's to identify objets with readable ID's but NOT incrementals (first objet 10001, second 10002), the way 542A4B243J, C63426KJ70, O30V4U1I9P, etc is fine. The ID's are needed to be primary keys on (at least) 6 MySQL tables. Objets are created with PHP in the same server.

@ta.speot.is

I wrote "don't see a reliable PHP script doing the job. Someone knows a tested class??" I don't think everything code in appear in google are tested, have you tested all the links maybe??

@sarnold

Thanks but I'm sorry, didn't understood well =(

punchi
  • 41
  • 6
  • 4
    You'll need to explain your requirements in detail to get a useful answer. For example, do you need to be able to generate IDs from a large number of totally uncoordinated locations and have them still be unique? Or can you assign each ID assigner a prefix so it reduce the problem to a locally unique ID? Can they save state and pick up where they left off? Or must it be purely random? Can it be time based? And so on. – David Schwartz Apr 25 '12 at 23:06
  • http://www.google.com.au/search?rlz=1C1_____enAU376AU376&sourceid=chrome&ie=UTF-8&q=php+ascii85 – ta.speot.is Apr 25 '12 at 23:06
  • Don't forget to convert your UUID from the 36-byte "usual style" into an integer in the range `0`-`2^128 - 1` -- you don't necessarily _have_ to work with a 128-bit integer but you must at least work on the input in proper four-byte chunks as if it were 128 bits long. – sarnold Apr 25 '12 at 23:17

1 Answers1

0

I faced the same problem for an enterprise project I was working on, and I couldn't find a reasonable tested and fast solution in PHP. So I decided to write a PHP extension which can be used to encode/decode data with base85/ascii85.

You can check it out here: https://github.com/miezuit/php-base85

It is tested using a set of automated tests.

Radu Gasler
  • 1,006
  • 14
  • 17