php generates the code for the locally unique identifier LUID

  • 2020-05-24 05:18:25
  • OfStack

GUID UUID (Universally Unique Identifier), was hope throughout time and space can produce only 1 identification number, which is necessary in a distributed computing environment. However, if just want to by qualified in a local environment, to generate a local only identification number "1", using UUID was killed on the wheel, the "local only 1 identification number", what I call the LUID (Local Unique Identifier)

For example, when I was developing website application with php, in order to avoid the name conflict of session caused by the user opening the same page for many times at the same time, Instead of $_SESSION['param'], I want to save $_SESSION[$luid]['param'], and pass $luid [$luid]['param'] by other means to ensure that the 'param' parameter is not overwritten. Considering that it is a limited environment in SESSION space, the strength of its uniqueness need not be too high, as long as it is only 1 within the lifetime of the same SESSION, I have the following code:

 
/** 
*  return 1 A wei 1 Unique in the local system 1 There is no 2 The string , 
*  Returns the 32 A string of characters , Form such as '7dac352074f221f3edc74d265c65a636', or 'd198d8fc56ffed627f3f8313d6f06acf' 
*/ 
function LUID(){ 
return MD5(microtime()); 
} 


It's just one line.return MD5(microtime());

The string returned by microtime() is already unique to 1, I tested 1, even if the continuous execution of microtime(), the return value has a difference of more than 100us, and the user clicks, and then passes it on the network and is processed by the server far more than a few 10ms. Adding md5 only makes the result messy.

Related articles: