How does PHP obtain the unique requestid of each HTTP request operated by a user?

Source: Internet
Author: User
Tags echo date
How does PHP obtain the unique requestid of each HTTP request operated by a user? No matter how many people, each click is required to be globally unique ID. How does PHP obtain the unique request id of each HTTP request operated by the user?
No matter how many people, each click is required to be a globally unique ID.

Reply content:

How does PHP obtain the unique request id of each HTTP request operated by a user?
No matter how many people, each click is required to be a globally unique ID.

Each time a request comes over, you generate a unique id, which can be used as the unique id of the request.uuidOrguidAnd so on

Hello, LZ:
When you see your problem, I first think of the primary key id concept, which can uniquely identify each record. Therefore, you need to find an incremental id to identify each request.

Solution 1: Use the PHP built-in global variable $ _ SERVER parameter REQUEST_TIME)
  '; Echo date ('Y-m-d H: I: s', $ _ SERVER ['request _ time']); // obtain the REQUEST start TIME

Output result:

11:27:06 11:27:01 // request time, which is 5 seconds different from the output date after sleep, as expected

Note: If the request volume is huge and cannot be identified in seconds, you can use the REQUEST_TIME_FLOAT parameter, which can be accurate to microseconds.

Solution 2: Use the php built-in function uniqid () to generate a unique id. Or generate: md5 (time (). mt_rand)


  

Phpsessid

1. Enable session,$sid = session_id();
2. Get the current request time$rid = $_SERVER['REQUEST_TIME_FLOAT']
3. The unique request equals$unqidId = md5($sid . $rid)// (If you still feel unreliable, add a random number)

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.