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 patch-ext_standard_uniqid.c for Performance problem Bug #74851

Patch version 2017-07-04 03:20 UTC

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

Obsoleted by 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-07-02 07:47:20.000000000 +0200
+++ ext/standard/uniqid.c	2017-07-02 08:03:12.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,29 @@
 							  &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;
+	char *str;
+	uint32_t status;
+	
+	if (uuidgen(&uuid, 1) == 0) {
+		uuid_to_string(&uuid, &str, &status);
+		if (status == 0 && str != NULL) {
+			uniqid = strpprintf(0, "%s%s", prefix, str);
+			free(str);
+			RETURN_STR(uniqid);
+		}
+	}
+	php_error_docref(NULL, E_WARNING, "uuidgen failure");
+	RETURN_FALSE;
+#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-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 22:01:26 2024 UTC