PHP time () and $_server[request_time] usage distinguishes _php skills

Source: Internet
Author: User
Tags echo date php script

This article describes in detail the difference between time () and $_server[request_time] usage in PHP. Share to everyone for your reference. The specific analysis is as follows:

The simple Time () and $_server["Request_time"] are all time, but it returns the current Unix timestamp and $_server["Request_time" to get the timestamp at the start of the request, slightly different.
1. Time () Gets the current system timestamp

int time (void):

Returns the current UNIX timestamp (returns the number of seconds since the Unix era (GMT January 1, 1970 00:00:00) to the current time. )

The timestamp that originated at the time of the request was saved from PHP 5.1 in $_server[' Request_time '.

$_server["Request_time"]: The timestamp of the start of the REQUEST. Available since PHP 5.1.0. I can see the explanation.

2. $_server["Request_time"] gets the time stamp at the start of the request

Instance code:

Copy Code code as follows:
<?php
Date_default_timezone_set (' PRC ');
Sleep (5);//php script sleeps 5 seconds
echo Date (' y-m-d h:i:s ', Time ());//get timestamp of current system time
echo ' echo Date (' y-m-d h:i:s ', $_server[' request_time ');/time stamp when requesting this PHP script
?>

The results of the output screenshot are as follows:

Conclusion:

Because Sleep (5) Sleeps for 5 seconds, and then gets the system timestamp with time (), $_server[' Request_time ' records the timestamp at the time the request was initiated. So $_server[' Request_time '] is 5 seconds earlier than the timestamp obtained with time ()

I hope this article will help you with your PHP program design.

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.