|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37106 uniqid() without more_entropy extremally slow
Submitted: 2006-04-17 14:52 UTC Modified: 2006-05-28 12:34 UTC
From: webmaster at polskabizuteria dot pl Assigned:
Status: Not a bug Package: Performance problem
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
10 - 2 = ?
Subscribe to this entry?

 [2006-04-17 14:52 UTC] webmaster at polskabizuteria dot pl
Uniquid() without second parameter (more_entropy) set as true is extremaly slow (approx 500 times)

Reproduce code:
/* SLOW */


/* FAST */



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-28 12:34 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

uniqid() is meant to give you a certrain id distribuion that is not predicable. That is uniqid() must neither generate two identical ids nor have a constant or in any way predictable difference between two calls. To ensure this we use usleep() internally to either force a thread (windows) or process (*nix) switch. On some systems the operating system has a slow implementation of this. However distrubition this much more important than the security risks implied.
 [2013-10-10 15:18 UTC] scott dot baker at gmail dot com
$loop = 10000;

print "uniqid('') x $loop = " . bench('gen_uniqid',$loop) . " seconds<br />";
print "uniqid('',true) x $loop = " . bench('gen_uniqid_entropy',$loop) . " seconds<br />";

function gen_uniqid() {
   return uniqid('');

function gen_uniqid_entropy() {
   return uniqid('',true);

function bench($func,$times) {
   $start = microtime(1);

   for ($i = 0; $i < $times; $i++) {

   $end = microtime(1);
   $ret = sprintf("%0.4f",$end - $start);

   return $ret;


uniqid('') x 10000 = 1.5876 seconds
uniqid('',true) x 10000 = 0.0329 seconds

Telling uniqid() to use more_entropy is MORE than 48 times faster
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 18:01:32 2024 UTC