Edit report at https://bugs.php.net/bug.php?id=27182&edit=1
ID: 27182
Comment by: cmbecker69 at gmx dot de
Reported by: sagawa at sohgoh dot net
Summary: [Patch] uniqid("prefix", 0) now works under recent
cygwin
Status: Feedback
Type: Feature/Change Request
Package: *General Issues
Operating System: CYGWIN_NT-5.1 1.5.7
PHP Version: 4.3.5RC2
Block user comment: N
Private report: N
New Comment:
I have now recompiled PHP 5.4.19 with the patch given above:
$ php -r 'var_dump(uniqid(null, false));'
string(13) "5228be262625a"
Previous Comments:
------------------------------------------------------------------------
[2013-09-05 13:22:37] cmbecker69 at gmx dot de
I made the following test:
$ uname -a
CYGWIN_NT-5.1 RELIANT 1.7.18(0.263/5/3) 2013-04-19 10:39 i686 Cygwin
$ php -v
PHP 5.4.19 (cli) (built: Aug 23 2013 19:12:30)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
$ php -r 'var_dump(uniqid(null,false));'
PHP Warning: uniqid(): You must use 'more entropy' under CYGWIN
in Command line code on line 1
Warning: uniqid(): You must use 'more entropy' under CYGWIN
in Command line code on line 1
bool(false)
>From looking at the sources[1], the result is not surprising.
[1] <http://lxr.php.net/xref/PHP_5_4/ext/standard/uniqid.c#63>
<http://lxr.php.net/xref/PHP_5_5/ext/standard/uniqid.c#63>
------------------------------------------------------------------------
[2013-07-31 01:39:26] [email protected]
Please try using this snapshot:
http://snaps.php.net/php5.4-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2004-02-08 00:40:54] sagawa at sohgoh dot net
Description:
------------
According to cygwin-patches(*1) and ChangeLog(*2), Cygwin's usleep now advances
system clock(gettimeofday).
*1 .. http://sources.redhat.com/ml/cygwin-patches/2003-q3/msg00178.html
*2 ..
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/signal.cc?cvsroot=src#rev1.48
Therefore I can use uniqid safely when more entropy flag is zero, I made a
patch. (but "more entropy flag" is still on by default for backward
compatibility)
Unfortunary cygwin doesn't change version for this change, I apply most recent
change of CYGWIN_VERSION_API_MINOR.
"String functions [tests/strings/001.phpt]" now pass!
--- php-4.3.5RC2/ext/standard/uniqid.c.orig 2003-01-01 01:35:35.000000000
+0900
+++ php-4.3.5RC2/ext/standard/uniqid.c 2004-02-08 13:01:49.006220800 +0900
@@ -34,6 +34,9 @@
#else
#include <sys/time.h>
#endif
+#if defined(__CYGWIN__)
+#include <cygwin/version.h>
+#endif
#include "php_lcg.h"
#include "uniqid.h"
@@ -66,7 +69,7 @@
}
#if HAVE_USLEEP && !defined(PHP_WIN32)
if (!more_entropy) {
-#if defined(__CYGWIN__)
+#if defined(__CYGWIN__) && (CYGWIN_VERSION_API_MINOR < 91)
php_error_docref(NULL TSRMLS_CC, E_ERROR, "You must use 'more
entropy' under CYGWIN.");
return;
#else
--- php-4.3.5RC2/tests/strings/001.phpt.orig 2001-03-21 21:47:46.000000000
+0900
+++ php-4.3.5RC2/tests/strings/001.phpt 2004-02-08 13:23:53.320491200 +0900
@@ -181,8 +181,8 @@
echo "Testing uniqid: ";
$str = "prefix";
-$ui1 = uniqid($str);
-$ui2 = uniqid($str);
+$ui1 = uniqid($str, 0);
+$ui2 = uniqid($str, 0);
if (strlen($ui1) == strlen($ui2) && strlen($ui1) == 19 && $ui1 != $ui2) {
echo("passed\n");
} else {
Reproduce code:
---------------
<?php
echo uniqid("prefix"),"\n";
echo uniqid("prefix", 1),"\n";
echo uniqid("prefix", 0),"\n";
echo uniqid("prefix", 0),"\n";
echo uniqid("prefix", 0),"\n";
?>
Expected result:
----------------
-- cygwin --
prefix4025c46680d100.85790027
prefix4025c466810f81.04902838
prefix4025c466814e0
prefix4025c466818c8
prefix4025c46681cb0
-- linux --
prefix4025c4a472847
prefix4025c4a47289a3.07476264
prefix4025c4a47766a
prefix4025c4a47c487
prefix4025c4a4812a8
Actual result:
--------------
-- cygwin(NG) --
PHP Fatal error: uniqid(): You must use 'more entropy' under CYGWIN. in
/home/sagawa/uniqid_test.php on line 4
prefix4025c46680d100.85790027
prefix4025c466810f81.04902838
-- linux(OK) --
prefix4025c4a472847
prefix4025c4a47289a3.07476264
prefix4025c4a47766a
prefix4025c4a47c487
prefix4025c4a4812a8
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=27182&edit=1