The HP uniqid () function can be used to generate a unique identifier that is not duplicated, based on the current timestamp at the microsecond level. In the case of high concurrency or long intervals (such as looping code), there is a large amount of duplicate data. Even if the second parameter is used, it repeats, and the best scenario is to combine the MD5 function to generate a unique ID.
PHP uniqid () generates a method that does not duplicate unique identification
This method produces a large amount of duplicate data, running the following PHP code, the array index is the unique identifier produced, and the corresponding element value is the number of repetitions of that unique identity.[PHP] View plain copy <?php $units = array (); for ($i =0; $i <1000000; $i + +) { $units [] = uniqid (); } $values = array_count_values ($units); $duplicates = []; foreach ($values as $k => $v) { if ($v >1) { $duplicates[$k]= $v; } } echo ' <pre> '; print_r ($duplicates); echo ' </pre> '; ?>
PHP uniqid () generate duplicate unique identification method two
This method generates a significant reduction in the number of unique identification duplicates.
[PHP] View plain copy <?php $units = array (); for ($i =0; $i <1000000; $i + +) { $units [] = uniqid (', true '); } $values = array_count_values ($units); $duplicates = []; foreach ($values as $k => $v) { if ($v >1) { &nBSP; $duplicates [$k]= $v; } } echo ' <pre> '; print_r ($duplicates); echo ' </ Pre> '; ?>
PHP uniqid () generate distinct unique identification method three
There are no duplicates in the unique identification generated by this method.
<?php
$units = Array ();
For ($i =0 $i <1000000; $i + +) {
$units []=md5 (Uniqid (MD5 (Microtime (TRUE)), true);
}
$values = Array_count_values ($units);
$duplicates = [];
foreach ($values as $k => $v) {
if ($v >1) {
$duplicates [$k]= $v;
}
}
Echo ' <pre> ';
Print_r ($duplicates);
Echo ' </pre> ';
?>