php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #74851
Patch 0001-uniqid-performance-fix.patch revision 2017-07-19 02:40 UTC by manu at netbsd dot org
Patch patch3-ext_standard_uniqid.c revision 2017-07-08 14:47 UTC by manu at netbsd dot org
Patch patch2-ext_standard_uniqid.c revision 2017-07-05 15:49 UTC by manu at netbsd dot org
Patch patch-ext_standard_uniqid.c revision 2017-07-04 03:20 UTC by manu at netbsd dot org

Patch patch2-ext_standard_uniqid.c for Performance problem Bug #74851

Patch version 2017-07-05 15:49 UTC

Return to Bug #74851 | Download this patch
This patch is obsolete

Obsoleted by patches:

This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: manu@netbsd.org

$NetBSD$

Use uuidgen(2) if available for generating unique Id. It may be much
faster than PHP default implentation, which makes an usleep(3) call
that may wait up to one schedule slice where 1 microsecond is requested.

--- configure.orig	2017-07-02 07:44:48.000000000 +0200
+++ configure	2017-07-02 07:45:23.000000000 +0200
@@ -14397,8 +14397,9 @@
 tzset \
 unlockpt \
 unsetenv \
 usleep \
+uuidgen \
 utime \
 vsnprintf \
 vasprintf \
 asprintf \
@@ -68216,9 +68217,9 @@
 
   fi
 
 
-      for ac_func in usleep nanosleep
+      for ac_func in usleep uuidgen nanosleep
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
 if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
--- configure.in.orig	2017-07-02 07:44:29.000000000 +0200
+++ configure.in	2017-07-02 07:44:41.000000000 +0200
@@ -692,8 +692,9 @@
 tzset \
 unlockpt \
 unsetenv \
 usleep \
+uuidgen \
 utime \
 vsnprintf \
 vasprintf \
 asprintf \
--- main/php_config.h.in.orig	2017-07-02 07:46:20.000000000 +0200
+++ main/php_config.h.in	2017-07-02 07:46:40.000000000 +0200
@@ -2013,8 +2013,11 @@
 
 /* Define to 1 if you have the `usleep' function. */
 #undef HAVE_USLEEP
 
+/* Define to 1 if you have the `uuidgen' function. */
+#undef HAVE_UUIDGEN
+
 /* Define to 1 if you have the `utime' function. */
 #undef HAVE_UTIME
 
 /* Define to 1 if you have the `utimes' function. */
--- ext/standard/uniqid.c.orig	2017-06-07 10:09:31.000000000 +0200
+++ ext/standard/uniqid.c	2017-07-05 17:20:38.000000000 +0200
@@ -33,8 +33,12 @@
 #include "win32/time.h"
 #else
 #include <sys/time.h>
 #endif
+#ifdef HAVE_UUIDGEN
+#include <sys/types.h>
+#include <sys/uuid.h>
+#endif
 
 #include "php_lcg.h"
 #include "uniqid.h"
 
@@ -58,8 +62,23 @@
 							  &more_entropy)) {
 		return;
 	}
 
+#if HAVE_UUIDGEN
+	/* Use uuidgen(2) if available. It is faster, since usleep(3)
+	 * may wait for a whole schedule slice, and is meant to produce
+	 * unique identifiers.
+	 */
+	struct uuid uuid;
+	
+	if (!more_entropy && uuidgen(&uuid, 1) == 0) {
+		uniqid = strpprintf(0, "%s%08x%04x%04x", prefix,
+				    uuid.time_low, uuid.time_mid,
+				    uuid.time_hi_and_version);
+		RETURN_STR(uniqid);
+	}
+#endif
+
 #if HAVE_USLEEP && !defined(PHP_WIN32)
 	if (!more_entropy) {
 #if defined(__CYGWIN__)
 		php_error_docref(NULL, E_WARNING, "You must use 'more entropy' under CYGWIN");
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Mar 22 20:01:27 2019 UTC