Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95972 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4335 invoked from network); 13 Sep 2016 05:46:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Sep 2016 05:46:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ohgaki.net designates 180.42.98.130 as permitted sender) X-PHP-List-Original-Sender: yohgaki@ohgaki.net X-Host-Fingerprint: 180.42.98.130 ns1.es-i.jp Received: from [180.42.98.130] ([180.42.98.130:39388] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/57-60695-1B297D75 for ; Tue, 13 Sep 2016 01:46:27 -0400 Received: (qmail 99283 invoked by uid 89); 13 Sep 2016 05:46:22 -0000 Received: from unknown (HELO mail-qt0-f169.google.com) (yohgaki@ohgaki.net@209.85.216.169) by 0 with ESMTPA; 13 Sep 2016 05:46:22 -0000 Received: by mail-qt0-f169.google.com with SMTP id 11so84135185qtc.0 for ; Mon, 12 Sep 2016 22:46:21 -0700 (PDT) X-Gm-Message-State: AE9vXwPNV56L38xVlgsZyMwZ2BnOz2oNQI10hFD9VDE3QIFF59qDKMBpMs8SHCUJ2AIEf3lLIHMr1SYJijxDWA== X-Received: by 10.200.41.54 with SMTP id y51mr25005182qty.83.1473745575977; Mon, 12 Sep 2016 22:46:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.84.168 with HTTP; Mon, 12 Sep 2016 22:45:35 -0700 (PDT) In-Reply-To: <87mvjcbfcb.fsf@lil.giraffy.jp> References: <878tuxenl4.fsf@lil.giraffy.jp> <87twdlcs2j.fsf@lil.giraffy.jp> <87h99lch13.fsf@lil.giraffy.jp> <877fagczci.fsf@lil.giraffy.jp> <87mvjcbfcb.fsf@lil.giraffy.jp> Date: Tue, 13 Sep 2016 14:45:35 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Kazuo Oishi Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Improve uniqid() uniqueness From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi Kazuo, On Tue, Sep 13, 2016 at 1:20 PM, Kazuo Oishi wrote: > The uniqid() manual explicitly say, > > - default value of more_entropy is false > > - the returned string will be 13 characters long. If more_entropy is > TRUE, it will be 23 characters. > > - if more_entropy is set to TRUE, uniqid() will add additional entropy > (using the combined linear congruential generator) at the end of the > return value > > http://php.net/manual/en/function.uniqid.php > > So, it is fairly valid to design > - field length limit to 13 chars in validation code or DB column. > - acceptable character type limit to "[0-9A-Za-z]+". > - expect increasing value > in their PHP applications. It's legacy design. php_combined_lcg() must not be used, especially functions like uniqid(). i.e. It's supposed to generate unique ID based on time, but php_combined_lcg() generates pseudo random from current time. It's more than obvious it's legacy and obsolete today. >> Anyway, let's talk BC with real code. >> >> I didn't look into all, but only briefly. >> https://searchcode.com/?q=uniqid&loc=0&loc2=10000&lan=24 > > Why didn't you... > You said "BC (BC break) will be minimum"... Why should I look into all? Show me the real code that breaks if you insist this minor BC matters. I can think of number of way to be broken, but I cannot imagine real production codes that are broken by change. BTW, the current manual states uniqid() return unique identifier. This is false. I updated the manual, but we should do better job to generate almost unique ID. &reftitle.returnvalues; - Returns the unique identifier, as a string. + Returns timestamp based unique identifier as a string. + + + This function tries to create unique identifier, but it does not + guarantee 100% uniqueness of return value. + + Current implementation is good enough for most cases, but it can be better. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net