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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC