Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use php to generate local unique identification code LUID

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report