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.uuid
Orguid
And 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)