From: Operating system: any PHP version: Irrelevant Package: Unknown/Other Function Bug Type: Feature/Change Request Bug description:Uniqid is not unique --
Description: ------------ --- >From manual page: http://www.php.net/function.uniqid%23Description --- Basically, I find it useful to have UUID's that can at the very least be unique in a controlled environment. As in, being able to have unique id's within a limited set of machines(I picked 32bits for the machine id, carefully distributed by me and intended to be unique, not based on MAC which can/must sometimes be spoofed for other purposes). In order to achieve that, several parts are required: -> machine unicity -> thread unicity -> thread time unicity -> inside-thread unicity The reason I picked those variables is very easy : -> machine id is a preset variable -> thread id is a readily available variable (you can pre-store it @ start of thread) -> thread time unicity (same you can pre-set it @ start) to avoid mixing thread 1234 from 12 o'clock with thread 1234 from 16 o'clock (with the time id which is in milli or microseconds, you can be sure that ending your thread with a very small sleep will prevent any possibility of two threads on the same time point) -> inside thread unicity (counter... of course you always have at least a counter going somewhere for some reason, so might as well use it) So basically, I picked 4 variables which are almost free to get (machine_id is present even before thread execution, thread_id is present @ thread creation, and thread_time is present @ thread creation too, the counter is almost inevitably present if you're handling several objects) in terms of processing power, but can also guarantee unicity. This can be guaranteed to be unique, as long as your time is unique (and if it is not, you have so many problems beyond unique identification it's not worth focusing on it -- ), and from my calculations, that type of unique id is safe for the next 20+ years according to processing power growth (although at some point threads_id's might get another digit). Besides, this method of generating unique id's is orders of magnitude faster, as it requires only very minor cpu activity (no random, no hash, no time variable generation on every id, etc. etc.) -> the most expensive operations have to be on the base16 encode / concat side. I have my own code for generating UUID's, however I believe it would be interesting to upgrade the UUID function in PHP to propose something as efficient and unique. Test script: --------------- // No script is required when a function is by it's nature not generating unique id's Expected result: ---------------- Absolutely nothing -- Edit bug report at https://bugs.php.net/bug.php?id=55391&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55391&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55391&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55391&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55391&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55391&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55391&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55391&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55391&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55391&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55391&r=support Expected behavior: https://bugs.php.net/fix.php?id=55391&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55391&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55391&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55391&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55391&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=55391&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55391&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55391&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55391&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55391&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55391&r=mysqlcfg
