In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how php generates a unique id. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. Md5 (time (). Mt_rand (110000000)
There is a certain probability that this method will be repeated.
2. Php built-in function uniqid ()
The uniqid () function generates a unique ID based on the current time in microseconds.
There is a sentence in the w3school reference manual: "the ID generated by this function is not optimal because it is based on system time. To generate an absolutely unique ID, use the md5 () function."
The following method returns a similar result: 5DDB650F-4389-F4A9-A100-501EF1348872
Function uuid () {if (function_exists ('com_create_guid')) {return com_create_guid ();} else {mt_srand ((double) microtime () * 10000); / / optional for php 4.2.0 and up. Feel free to sow any number of seeds. You won't need them after 4.2.0. $charid = strtoupper (md5 (uniqid (rand (), true); / / generate a unique id based on the current time (millisecond). $hyphen = chr (45); / / "-" $uuid =''. / / chr / / "{" substr ($charid, 0,8). $hyphen. Substr ($charid, 8,4). $hyphen. Substr ($charid, 12,4). $hyphen. Substr ($charid, 16,4). $hyphen. Substr ($charid, 20,12); / / .chr (125); / / "}" return $uuid;}}
Com_create_guid () is the only id method that comes with php, which seems to be gone after php5.
3. The official uniqid () reference manual has a method provided by the user, and the result is similar: {E2DFFFB3-571E-6CFC-4B5C-9FEDAAF2EFD7}
Public function create_guid ($namespace =') {static $guid =''; $uid = uniqid ("", true); $data = $namespace; $data. = $_ SERVER ['REQUEST_TIME']; $data. = $_ SERVER [' HTTP_USER_AGENT']; $data. = $_ SERVER ['LOCAL_ADDR']; $data. = $_ SERVER [' LOCAL_PORT']; $data. = $_ SERVER ['REMOTE_ADDR']; $data. = $_ SERVER [' REMOTE_PORT'] $hash = strtoupper (hash ('ripemd128', $uid. $guid. Md5 ($data)); $guid ='{'. Substr ($hash, 0,8). '-'. Substr ($hash, 8,4). '-'. Substr ($hash, 12,4). '-'. Substr ($hash, 16,4). '-'. Substr ($hash, 20,12). '}'; return $guid;} Thank you for reading! This is the end of this article on "how php generates a unique id". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.