This is the case for php remote school. 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, 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.