PHP Remote school hours

Source: Internet
Author: User
In this case, we need a very reliable current time to support it. Although the time of most servers is very accurate, we use time () the time obtained is reliable, but it is inevitable that there will be inaccurate situations. Some servers do not enable NTP (Network Time Protocol) for time synchronization, and due to hardware environment and other factors, as a result, the time is varied, which is usually a few minutes or a maximum of several hours, because the same time is used on the same website, but sometimes it is so bad. On the Internet, there is a free time service dedicated to providing UTC time correction. The NTP protocol is used. For more information, see the previous link. The time error provided by him is about 20 ms (not to mention the time consumed during data transmission, which has long been taken into consideration by NTP, we can have a very credible current time.

Now let's take a look at how PHP can get a very accurate UTC time. Since the NTP protocol is a little bit difficult to use, we have a better protocol that can be used, it is the daytime protocol Protocol, through which we can directly obtain text data, which makes processing more convenient. We use the time.nist.gov Time Service. The code is very simple. We can use TCP to connect to Port 13.

$ Fp = fsockopen ('time .nist.gov ', 13, $ errno, $ errstr, 90); echo fread ($ FP, 2096 );

The obtained data is similar to the following:

54979 09-05-28 09:10:50 50 0 0 206.9 UTC (NIST )*

Each part of this string makes sense. For details, refer to callback.

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.