What is the probability of not the only identifier in the loop

I iterate over the array and for each record generates a unique identifier with uniqid:

foreach($emailsByCampaign as $campaign => $emails) {
    $campaignHex = $this->strToHex($campaign);
    $values = "(";
    for ($i=0; $i<sizeof($emails);$i++) {
        $values .= $analyticsDbInstance->escape($emails[$i]) . ",'" . uniqid(true) . "'), (";
    }
}

The official documentation states that it uniqidgenerates idbased on microseconds. What is the likelihood that two cycles of the cycle will pass in less than two seconds, leading to unique identifiers?

+4
source share
1 answer

uniqid() , Unix - 1 1970 . . ( ), uniqid(), , .

PHP UUID ( GUID), , , UUID V4, ( )

- , openssl-random-pseudo-bytes()

+4

Source: https://habr.com/ru/post/1524269/


All Articles