Is time () a guaranteed jump sign?

The PHP manual states that time() returns & puncsp; " current UNIX timestamp " & thinsp; & # xfeff; α΄€ & puncsp; & shy; and microtime() returns & puncsp; " current Unix microsecond timestamp " & thinsp; & # xfeff; Κ™ .

However, are these features guaranteed to behave like those that strictly comply with POSIX.1 systems ?

In particular, do jumps of seconds to insert so that the result is time() & hairsp; | ? hairsp; & shy; microtime() jump back 1 second at the beginning of the next day, (also at the end of the second jump), giving us repeatable return values ​​- as opposed to fresh unique values ​​- throughout the first second of this next day?

For example, if we poll time() & hairsp; | ? hairsp; & shy; microtime() every microsecond throughout the 1998 period and # xfeff; -12 & # xfeff; -31 and 1999 & # xfeff; -01 & # xfeff; 01, there would be two occurrences of each value in the range 915 & # xfeff; 148 & # xfeff; 800 & # xff1c; & # xfeff; & # xff1d; x & # xff1c; 915? & # xfeff; 148 & # xfeff ;? 801

+5
linux windows php time hhvm
source share
3 answers

PHP is a server language. The time () function will decide the system time of this server. If the server runs the NTP daemon, it will know the second level and adjust it accordingly. PHP does not know about this, but the system does.

+8
source share

The UNIX timestamp, since you get it from time () in PHP, is a kind of animal.

It took me a long time to figure this out, but it happens that the timestamp increases during the second jump, and when the second jump ends, the timestamp (but not UTC!) Jumps back one second.

This has some important implications:

  • You can always accurately convert from UTC to UNIX timestamp
  • You cannot always (for all time points) convert from a timestamp to UTC
  • The Unix timestamp is non-contiguous, meaning it is indented. (Or, conversely, it remains unchanged without an increase for 2 seconds.)
  • If you get a conversion with a conversion error from the UNIX timestamp to UTC, the error will be no more than 2 seconds. (This means that you may receive the wrong day.)
  • In retrospect, the Unix timestamp appears linear. This means that if you save time series data and you are not interested in one or two seconds per year that are not displayed correctly, you can consider the saved time data adjacent.

Bypass

What if the Unix timestamp did not bounce suddenly and stay the same for 2 seconds? This is exactly what Google has done for its servers. Their solution was to slowly distort the time of only a millisecond at a time for a long period of time, to make the second shift jump almost invisible to applications, (As for applications and operating systems on Google servers, the jump seconds are no longer inserted by IERS . )

+10
source share

time() just returns the UNIX timestamp. This means that it is not affected by leaps of seconds (and such), because you will never "waste" time, simply because someone decided this. Only textual representations occur (e.g. created using date() ).

+1
source share

All Articles