Jeremy Shaver - 2003-06-06

A user wrote and said that they had problems because the server's clock was being changed from UTC (zulu) time to "local" time and back again at various points. This caused problems with the scheduler because it never knew what the ACTUAL time was.

We provided this solution: The following patch can be used in place of the existing zulutime function in the functions.php file. It uses the NIST time server to get the current time. It will slow down the scheduler slightly, but provides an alternative to the local clock problem.

/----------------------------------------------------
// ZULUTIME
//return time stamp in mktime format for zulu time
function zulutime() {

    if ($GLOBALS['zulutime']=="") {

        $address = "131.107.1.10";
        $port    = 13;

        /* Create a TCP/IP socket. */
        $fp = fsockopen ($address, $port, $errno, $errstr, 30);
        if (!$fp) {
            echo "$errstr ($errno)<br>\n";
        } else {
            fputs ($fp, "GET / HTTP/1.0\r\n\r\n");

            $string = @fgets ($fp,128);
            $string = @fgets ($fp,128);
            $tok = strtok ($string," ");
            $date = strtok (" ");
            $time = strtok (" ");

            $GLOBALS['zulutime'] = strtotime($date . " " . $time);
            fclose ($fp);
        }
    }

    //if time wasn't correctly obtained from TCP/IP server, use server's clock
    if ($GLOBALS['zulutime']=="" | $GLOBALS['zulutime']<=0) $GLOBALS['zulutime'] = mktime();

    return $GLOBALS['zulutime'];

}