I have a system running on Ubuntu + Nginx + PHP5.3 + APC.
I have a function to generate a hash string used as UID to identify an entity
function rand_hex($length = 24)
{
$select = '0123456789abcdef';
$ret = '';
for ($i = 0; $i < $length; $i++)
$ret .= $select[rand(0,strlen($select)-1)];
return $ret;
}
Recently I started experiencing intermittent issues where multiple Entities shared the same UID generated. This happens 1 in about 50 times and when it happens, two entities are created within the same 1 hour window, and most of them happened within the same 5 second window. The two entities that shared the same UID can sometimes be created by different users (i.e. different accounts and different browsers )
It looks like the rand_hex function is kinda cached and generate same result. I've already search through the application for application logic error without success. I wonder if anyone has any clue . Thanks in advance.
NOTE: I know the code itself is not good and there are many better ways to generate UIDs. I am working with a legacy system.