php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14248 uniqid() is extremely slow (20ms per call)
Submitted: 2001-11-27 04:47 UTC Modified: 2001-11-27 04:53 UTC
From: bartvb at iae dot nl Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.0.5 OS: Linux 2.4.13-ac5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bartvb at iae dot nl
New email:
PHP Version: OS:

 

 [2001-11-27 04:47 UTC] bartvb at iae dot nl
A call to uniqid() seems to take approximately 20ms. In all that time the processor seems to be doing absolutely nothing (well, it seems to be waiting for something).

I wrote a convert script which uses uniqid() while testing it it took 40 seconds to convert 1600 items, without uniqid() the time went down to 3 seconds.. Quite a remarkable performance boost ;) Especially since the script was made to convert around 300.000 items.

Please speed up this function..

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-27 04:53 UTC] derick@php.net
The implementation of uniqid is as fast as it could be, so speeding it up is not really possible (without loosing randomness)
You can however try this:

$uniq = md5 (time());

This will not be that unique as uniqid, but it should be good enough.

Derick
 [2002-02-20 11:21 UTC] mikeboulet at newfangled dot com
This is still an issue with RH 7.1, PHP 4.0.6.
Performs fine under Windows 2000.

I would like to suggest that the performance issue be mentioned on uniqid() documentation. I probably spent a week looking at this issue. 

Our sites used the uniqid() function very heavily. This was a tough one to find! 

Just a thought to save someone else's sanity.

Mike Boulet
Newfangled Web Factory
www.newfangled.com
 [2002-04-22 10:28 UTC] christophe dot gras at idfr dot net
Here is what I noticed :

A call to uniqid("") takes between 12 and 20 ms.
A call to uniqid("",1) is extremely fast (below 1 ms).

In the code the only difference is, with no entropy, "usleep(1)". That's not explain the difference I found.

Why is it so long without entropy?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 22:01:27 2025 UTC