punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:

Multilateral Monks,

The plethora of possible functions for getting the current time on the server are great - so long as the clock on the server is set right. Having come to the conclusion that that my script cannot depend on the server admins keeping the server clock set right, I nonetheless need a reliable and correct timestamp for certain user events.

Is there some online service that can easily be referenced by a Perl script, and if so, how is it used?

Thanks.




Forget that fear of gravity,
Get a little savagery in your life.
Max Webster

Replies are listed 'Best First'.
Re: Reliable time reference for timestamp?
by liverpole (Monsignor) on May 14, 2007 at 14:57 UTC
    Hi punch_card_don,

    I haven't used it myself, but I'd be inclined to look at something like Net::NTP to start with.  It's an interface to NTP, which is the "Network Time Protocol".

    Update:  Using this as an excuse to try something new, I just installed Net::NTP from CPAN.

    Here's an example based on the documentation:

    use strict; use warnings; + use Data::Dumper; use Net::NTP; + my %response = get_ntp_response(); printf "NTP results => %s\n", Dumper(\%response); __END__ NTP results => $VAR1 = { 'Version Number' => 3, 'Root Delay' => '0.129638671875', 'Precision' => -16, 'Leap Indicator' => 0, 'Stratum' => 4, 'Receive Timestamp' => '1179155054.2939', 'Transmit Timestamp' => '1179155054.29393', 'Reference Timestamp' => '1179154736.59929', 'Originate Timestamp' => '1179155054.38672', 'Poll Interval' => '0.0000', 'Reference Clock Identifier' => '192.168.10.150', 'Root Dispersion' => '0.0000', 'Mode' => 4 };

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Reliable time reference for timestamp?
by kyle (Abbot) on May 14, 2007 at 14:57 UTC
Re: Reliable time reference for timestamp?
by Krambambuli (Curate) on May 14, 2007 at 15:35 UTC
    ... Having come to the conclusion that that my script cannot depend on the server admins keeping the server clock set right,...

    If time is such an important issue, it might be so for much more than your script... Don't let your admins get away: having a correct time on a server and keeping it in sync with the Network time is important.

    Being insistent on that, you might do a Good Thing for your other scripts, other customers scripts, your company, other users of that server, etc. Definitely persuade them to keep a good time on the server, even if you get a solution for your self as quick as writing a few lines of code.

    Use Net::NTP rather for sending your admin a mail as soon as the server's time is more then a few seconds away from the reference time :)
Re: Reliable time reference for timestamp?
by swampyankee (Parson) on May 14, 2007 at 19:42 UTC

    Yes. See NIST Internet Time Service. In the US, NIST is, more or less by definition, the correct time, disregarding network latencies.

    emc

    Insisting on perfect safety is for people who don't have the balls to live in the real world.

    —Mary Shafer, NASA Dryden Flight Research Center