Duplicate uniqid in PHP in high concurrency

Source: Internet
Author: User
Tags repetition
The uniqid in PHP is duplicate in high concurrency. recently, the token verification has been generated in the project. First, use the uniqid () function in php to generate random strings. However, this function is based on microsecond time. In the case of high concurrency, the same value may be generated.

Solution 1: uniqid (rand (). The first parameter of this function can be used as the prefix of the number of generations, which greatly reduces the repetition rate of the number of generators. But the possibility of repetition still exists.

Solution 2: md5 (uniqid (). use the md5 () function to generate an absolutely unique value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.