Home Blog Query Time from a NTP Server with PHP

Query Time from a NTP Server with PHP

4

A time server is a computer server that reads the precise time from a reference source and distributes this information to various clients. The most widely used protocol for distributing and synchronising time over the Internet is the Network Time Protocol (NTP), though other less-popular or outdated time protocols continue to be in use.

Your time can be synced to any number of NTP servers for the purpose of updating your own system time or querying it for another use. While most UNIX-based servers will support synchronising by default – many don’t… and some other smaller servers may not provide that feature at all. This PHP function is a means of obtaining a GPS-accurate time when other methods fail you.

Query Time from a NTP Server with PHP

Pictured: Windows has supported NTP updating since Windows 2000

You can choose any number of NTP servers to sync to here .

The PHP Function

Download

Title: Query Time from a NTP Server
Description: Query the Server Time from a NTP Server with PHP.
Download: PHP Code (V0.2) | Plugin Page

Shortt URL for this post: http://shor.tt/2nNE

4 COMMENTS

  1. Hello, i am from singapore. When i get the timing using your code, but when i retrieve it does not give me the correct time, the timing is late 8hrs, which related to the GMT +8 for Singapore. How can i fix it? I have already changed my host to 0.sg.pool.ntp.org which is a singapore server.

    • The time returned by an NTP server is always UTC, but the handling of the time is set by your server. So, the behaviour is likely as expected. If you’re working with code and need to revert back to UTC, just correct for the timezone variation. If you’re working with PHP, gmdate formats a GMT/UTC date/time.

    • Sorry, your message was filtered away with a few billion others in spam. If you’re getting a 500 error I’d suggest you check your server logs for errors. I suspect it’s a socket_connect() error generated by your host.

LEAVE A REPLY

Please enter your comment!
Please enter your name here