简体   繁体   中英

Time in mysql and php on two different servers

I have my php site on a server and database on another, I want to check the time on the other server holding the database, this way i can synchronize both servers at the same time to avoid time gaps.

For my current server i simply do time(). But how i can get time for mysql database?

This is an operational problem which needs to be solved by your operations engineers (for example, using NTP). Operations should also monitor clock sync.

It is reasonable to develop your application assuming that the clocks will stay (mostly) in sync.

I normally like to assume that

  • Clocks will be synchronised to within a few seconds
  • Clocks never run backwards by more than a few seconds

I guess if you assume those, you're going to be alright.

However you can do

SELECT UNIX_TIMESTAMP()

You can use a combination of NOW() and TIME() to fetch the time from the database server. Have a look at the supported date and time functions that MySQL supports.

SELECT TIME(NOW());

The above should work fine for you.

我认为您想在服务器之间进行同步,在这种情况下,最好使用NTP服务器

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM