PHP Client Connection Time: Get Request Time Easily
In PHP, you can retrieve the client connection time by accessing the REQUEST_TIME value in $_SERVER. This value represents the time when the client initiated the request and can be used to calculate the client connection time. Here is an example code:
// 获取客户端连接时间
$clientConnectTime = $_SERVER['REQUEST_TIME'];
// 计算连接时间
$currentTime = time();
$connectionTime = $currentTime - $clientConnectTime;
echo "客户端连接时间为:$connectionTime 秒";
In the code above, the client request time is first obtained using $_SERVER[‘REQUEST_TIME’], then the current time is obtained using the time() function, and finally the time difference between the two is calculated to determine the client connection time.