Req #74851 [NEW]: uniqid performances

From: Date: Tue, 04 Jul 2017 03:19:54 +0000
Subject: Req #74851 [NEW]: uniqid performances
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209794@lists.php.net to get a copy of this message
From: manu at netbsd dot org Operating system: NetBSD PHP version: 7.1.6 Package: Performance problem Bug Type: Feature/Change Request Bug description:uniqid performances Description: ------------ uniqid() uses system microsecond-precise clock to produce an unique identifier. In order to avoid producing the same value, it will always call usleep() to wait for the next microsecond. The problem here is that usleep() may wait for much longer. According to Opengroup's POSIX, "The suspension time may be longer than requested due to the scheduling of other activity by the system". Indeed tests on NetBSD show that the kernel will schedule another process during the usleep() call, resulting in a typical uniqid() duration around 16 ms, which is around 16000 time slower than intended. I suggest to address the problem by using uuidgen() system call if available. This system call is not in POSIX standard, but will be available on most modern systems. The call costs around a microsecond, and it produce a much better unique identifier than what uniqid() currently does. Attached is a patch against PHP 7.1.6 that cause PHP's configure script to look up uuidgen(), and that uses it in uniqid() if it is available. The same problem was reported at lease in bugs #65626, #37106, #37840 and #14248, but with no satisfying fix proposed, in my opinion. Test script: --------------- Test to compare uniqid() performance across systems: time php -r 'for ($i = 0; $i < 1000; $i++) uniqid();' -- Edit bug report at https://bugs.php.net/bug.php?id=74851&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74851&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74851&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74851&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74851&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74851&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74851&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74851&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74851&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74851&r=support Expected behavior: https://bugs.php.net/fix.php?id=74851&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74851&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74851&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74851&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74851&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74851&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74851&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74851&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74851&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74851&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74851&r=mysqlcfg

« previous php.bugs (#209794) next »