Thank you for replying. The script I have tried most recently came from here.
<?php
// ******************************************************
// * NTP Interface Class for PHP *
// * (Written by Brian Haase on June 22, 2004 *
// * *
// ******************************************************
class NTP_Core
{
var $Server;
var $Port = 13;
var $Timeout = 30;
var $Time = "";
var $Timestamp = 0;
var $Error = "";
function lookup( $Server )
{
$this->Error = "";
$this->Server = $Server;
$_Success = FALSE;
$_Time = "";
$_Timeout = time();
$Fp = @fsockopen( $this->Server, $this->Port, $errno, $errstr, $this->Timeout );
if ( !$Fp )
{
$this->Error = $errno . " : " . $errstr;
return FALSE;
}
for ( ; time() <= ($_Timeout + $this->Timeout) ; )
{
$_Time .= fgets( $Fp, 2096 );
if ( feof( $Fp ) ) break;
}
if ( $Fp ) fclose( $Fp );
if ( $_Time <> "" )
{
$this->Time = trim($_Time);
return TRUE;
}
$this->Error = "N/A : NTP PHP Class Socket Timeout";
return FALSE;
}
function format( )
{
// Tue Jun 22 07:19:36 UTC 2004
// Tue Jun 22 07:19:51 2004
$_Fields = explode( ' ', $this->Time );
$_Subfields = explode( ':', $_Fields[3] );
// Discard the day of week - $_Fields[0];
$Month = $_Fields[1];
$Day = $_Fields[2];
$Hour = $_Subfields[0];
$Min = $_Subfields[1];
$Sec = $_Subfields[2];
if ( count( $_Fields ) == 6 ) {
$Zone = $_Fields[4];
$Year = $_Fields[5];
} else {
$Zone = "";
$Year = $_Fields[4];
}
$MTable = array( "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
$Month = array_search( $Month, $MTable );
$this->Timestamp = mktime( $Hour, $Min, $Sec, $Month, $Day, $Year );
return TRUE;
}
}
?>
and the test script updated to use a known good server pool.ntp.org. I have tried ports 13, 37, and 123.
<?php
//
// Basic Example Script for the NTP Class Module
//
// ::: KEEP IN MIND, THE CLASS DOES NOT YET HANDLE TIMEZONE CONVERSIONS :::
/// Depending on the server you use, you will need to apply your own GMT conversion to the timestamp.
//
require "ntp.class.php";
// Create the Class
$NTP = new NTP_Core;
// Request the time from a NTP Server
$Result = $NTP->lookup( "pool.ntp.org" );
if ( $Result == TRUE )
{
// Output the Server Time
echo "<B>Server Time: </B>" . $NTP->Time . "<BR>\n";
// Try to reformat the time into a useable timestamp
if ( $NTP->Format() )
{
echo "<B>Formatted: </B>" . date('l dS of F Y h:i:s A', $NTP->Timestamp);
}
else
{
echo "Bogus Time Format - Unable to Format.";
}
}
else
{
and the timeout message:
NTP Time Lookup Failed - 10060 : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.