Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use php to generate local unique identification code LUID

Shulou Source: shulou.com Published: 2022-06-03 07:46:53 10月03日 Update

This article will explain in detail how to use php to generate local unique identification code LUID, Xiaobian feels quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

UUID(Universally Unique Identifier),GUID are all expected to be able to generate unique identifiers in the entire space-time range, which is necessary in distributed computing environment. However, if you just want to generate a "local unique identifier" in a limited local environment, using UUID is a killing knife. This "local unique identifier", I call LUID(Local Unique Identifier)

For example, when I was developing a website program with php, in order to avoid the problem of session name conflict caused by users opening the same page multiple times at the same time, I wanted to save the session not $_SESSION <$'param '], but $_SESSION[$liquid]<$'param'], and then pass the $liquid value by other means to ensure that the 'param' parameter is not overwritten. Looking up the other people's solutions, are generated UUID, and generate UUID algorithm spread hundreds of lines. I consider that because it is in SESSION space, it is a limited environment, and its uniqueness strength does not have to be too high, as long as it is unique within the lifetime of the same SESSION, so I have the following code:

/**

* Returns a string unique to the local system,

* Return is a 32-character string of the form '7dac352074f221f3edc74d265c65 a636', or'd198d8fc56ffed627f3f8313d6f06acf'

*/

function LUID(){

return MD5(microtime());

}

return MD5(microtime());

The string returned by microtime() is already unique. I measured it, and even if microtime() is executed continuously, the return value has a difference of more than 100us, and the interval between the user clicking and passing it on the network and then being processed by the server is far more than tens of ms. Adding md5 just messes up the results.

About "how to use php to generate local unique identifier LUID" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Local identifier generation character string environment article way more good practical messy necessary sprinkle unique one line code user content internal energy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Xiaomi Huawei NVidia Shulou Information