Unverified Commit fcfdd281 authored by Jerome Boucher's avatar Jerome Boucher
Browse files

fix/15189 : rework uniqid to use only decimal parts of microseconds

parent 28fd13fe
Pipeline #9979 failed with stages
in 50 seconds
......@@ -44,23 +44,23 @@ function symlink($target, $link)
* Improvements : the use of base conversion to get short ids with good entropy
* @param string $prefix A prefix for the generated id, if a specific class of characters is needed (XML ids must start with alpha)
* @param bool $moreEntropy Use more entropy
*
*
* @return string The unique id
*/
function uniqid($prefix = "", $moreEntropy = true)
{
$parts = \explode('.', microtime(true));
$sec = $parts[0];
if (!isset($parts[1])) {
$parts = \explode(' ', microtime());
$sec = $parts[1];
if (!isset($parts[0])) {
$msec = 0;
} else {
$msec = $parts[1];
$msec = substr($parts[0], 2, 6);
}
$uniqid = str_pad(base_convert($sec, 10, 36), 6, '0', STR_PAD_LEFT) . '-' . str_pad(base_convert($msec, 10, 16), 4, '0', STR_PAD_LEFT);
$uniqid = str_pad(base_convert($sec, 10, 36), 6, '0', STR_PAD_LEFT) . '-' . str_pad(base_convert($msec, 10, 36), 4, '0', STR_PAD_LEFT);
if ($moreEntropy) {
$uniqid .= '-' . str_pad(base_convert(mt_rand(), 10, 36), 6, '0', STR_PAD_LEFT);
$uniqid .= '-' . str_pad(base_convert(mt_rand(), 10, 36), 6, '0', STR_PAD_LEFT);
}
return $prefix . $uniqid;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment