[英]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. 我在服务器上有我的php站点,在另一个服务器上有数据库,我想检查另一个拥有数据库的服务器上的时间,这样我就可以同时同步两个服务器以避免时间间隔。
For my current server i simply do time(). 对于我当前的服务器,我只是做time()。 But how i can get time for mysql database? 但是我如何获得MySQL数据库的时间呢?
This is an operational problem which needs to be solved by your operations engineers (for example, using NTP). 这是一个操作问题,您的操作工程师需要解决(例如,使用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 我通常想假设
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. 您可以结合使用NOW()和TIME()从数据库服务器获取时间。 Have a look at the supported date and time functions that MySQL supports. 看一下MySQL支持的日期和时间函数。
SELECT TIME(NOW());
The above should work fine for you. 上面应该适合您。
我认为您想在服务器之间进行同步,在这种情况下,最好使用NTP服务器 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.