25 #require_once 'Zend/TimeSync/Protocol.php'; 52 $this->_timeserver =
'udp://' . $timeserver;
70 $fracba = ($frac & 0xff000000) >> 24;
71 $fracbb = ($frac & 0x00ff0000) >> 16;
72 $fracbc = ($frac & 0x0000ff00) >> 8;
73 $fracbd = ($frac & 0x000000ff);
75 $sec = (
time() + 2208988800);
76 $secba = ($sec & 0xff000000) >> 24;
77 $secbb = ($sec & 0x00ff0000) >> 16;
78 $secbc = ($sec & 0x0000ff00) >> 8;
79 $secbd = ($sec & 0x000000ff);
83 $nulbyte = $nul . $nul . $nul . $nul;
84 $ntppacket = chr(0xd9) . $nul . chr(0x0a) . chr(0xfa);
92 $ntppacket .= $nul . $nul . chr(0x1c) . chr(0x9b);
100 $ntppacket .= $nul . chr(0x08) . chr(0xd7) . chr(0xff);
107 $ntppacket .= $nulbyte;
113 $ntppacket .= chr($secba) . chr($secbb) . chr($secbc) . chr($secbd);
114 $ntppacket .= chr($fracba) . chr($fracbb) . chr($fracbc) . chr($fracbd);
120 $ntppacket .= $nulbyte;
121 $ntppacket .= $nulbyte;
127 $ntppacket .= $nulbyte;
128 $ntppacket .= $nulbyte;
135 $ntppacket .= chr($secba) . chr($secbb) . chr($secbc) . chr($secbd);
136 $ntppacket .= chr($fracba) . chr($fracbb) . chr($fracbc) . chr($fracbd);
149 $f1 = str_pad(ord($input[0]), 2,
'0', STR_PAD_LEFT);
150 $f1 .= str_pad(ord($input[1]), 2,
'0', STR_PAD_LEFT);
151 $f1 .= str_pad(ord($input[2]), 2,
'0', STR_PAD_LEFT);
152 $f1 .= str_pad(ord($input[3]), 2,
'0', STR_PAD_LEFT);
164 $f1 = str_pad(ord($input[0]), 2,
'0', STR_PAD_LEFT);
165 $f1 .= str_pad(ord($input[1]), 2,
'0', STR_PAD_LEFT);
166 $f1 .= str_pad(ord($input[2]), 2,
'0', STR_PAD_LEFT);
167 $f1 .= str_pad(ord($input[3]), 2,
'0', STR_PAD_LEFT);
169 $f3 = ($f1 & 0x0001FFFF);
170 $f1 = $f2 .
'.' . $f3;
182 $f1 = (ord($input[0]) * pow(256, 3));
183 $f1 += (ord($input[1]) * pow(256, 2));
184 $f1 += (ord($input[2]) * pow(256, 1));
185 $f1 += (ord($input[3]));
188 $f2 = (ord($input[4]) * pow(256, 3));
189 $f2 += (ord($input[5]) * pow(256, 2));
190 $f2 += (ord($input[6]) * pow(256, 1));
191 $f2 += (ord($input[7]));
193 return (
float) ($f1 .
"." . $f2);
206 $flags = ord(fread($this->_socket, 1));
207 $info = stream_get_meta_data($this->_socket);
209 if (
$info[
'timed_out'] ===
true) {
210 fclose($this->_socket);
212 "'$this->_timeserver' on port '$this->_port', reason: 'server timed out'");
217 'stratum' => ord(fread($this->_socket, 1)),
218 'poll' => ord(fread($this->_socket, 1)),
219 'precision' => ord(fread($this->_socket, 1)),
220 'rootdelay' => $this->
_getFloat(fread($this->_socket, 4)),
221 'rootdispersion' => $this->
_getFloat(fread($this->_socket, 4)),
222 'referenceid' => fread($this->_socket, 4),
223 'referencestamp' => $this->
_getTimestamp(fread($this->_socket, 8)),
224 'originatestamp' => $this->
_getTimestamp(fread($this->_socket, 8)),
225 'receivestamp' => $this->
_getTimestamp(fread($this->_socket, 8)),
226 'transmitstamp' => $this->
_getTimestamp(fread($this->_socket, 8)),
227 'clientreceived' => microtime(
true)
262 $leap = ($binary[
'flags'] & 0xc0) >> 6;
265 $this->_info[
'leap'] =
'0 - no warning';
269 $this->_info[
'leap'] =
'1 - last minute has 61 seconds';
273 $this->_info[
'leap'] =
'2 - last minute has 59 seconds';
277 $this->_info[
'leap'] =
'3 - not syncronised';
286 $this->_info[
'version'] = ($binary[
'flags'] & 0x38) >> 3;
295 $mode = ($binary[
'flags'] & 0x07);
298 $this->_info[
'mode'] =
'symetric active';
302 $this->_info[
'mode'] =
'symetric passive';
306 $this->_info[
'mode'] =
'client';
310 $this->_info[
'mode'] =
'server';
314 $this->_info[
'mode'] =
'broadcast';
318 $this->_info[
'mode'] =
'reserved';
322 $ntpserviceid =
'Unknown Stratum ' . $binary[
'stratum'] .
' Service';
329 $refid = strtoupper($binary[
'referenceid']);
330 switch($binary[
'stratum']) {
332 if (substr($refid, 0, 3) ===
'DCN') {
333 $ntpserviceid =
'DCN routing protocol';
334 }
else if (substr($refid, 0, 4) ===
'NIST') {
335 $ntpserviceid =
'NIST public modem';
336 }
else if (substr($refid, 0, 3) ===
'TSP') {
337 $ntpserviceid =
'TSP time protocol';
338 }
else if (substr($refid, 0, 3) ===
'DTS') {
339 $ntpserviceid =
'Digital Time Service';
344 if (substr($refid, 0, 4) ===
'ATOM') {
345 $ntpserviceid =
'Atomic Clock (calibrated)';
346 }
else if (substr($refid, 0, 3) ===
'VLF') {
347 $ntpserviceid =
'VLF radio';
348 }
else if ($refid ===
'CALLSIGN') {
349 $ntpserviceid =
'Generic radio';
350 }
else if (substr($refid, 0, 4) ===
'LORC') {
351 $ntpserviceid =
'LORAN-C radionavigation';
352 }
else if (substr($refid, 0, 4) ===
'GOES') {
353 $ntpserviceid =
'GOES UHF environment satellite';
354 }
else if (substr($refid, 0, 3) ===
'GPS') {
355 $ntpserviceid =
'GPS UHF satellite positioning';
360 $ntpserviceid = ord(substr($binary[
'referenceid'], 0, 1));
361 $ntpserviceid .=
'.';
362 $ntpserviceid .= ord(substr($binary[
'referenceid'], 1, 1));
363 $ntpserviceid .=
'.';
364 $ntpserviceid .= ord(substr($binary[
'referenceid'], 2, 1));
365 $ntpserviceid .=
'.';
366 $ntpserviceid .= ord(substr($binary[
'referenceid'], 3, 1));
370 $this->_info[
'ntpid'] = $ntpserviceid;
377 switch($binary[
'stratum']) {
379 $this->_info[
'stratum'] =
'undefined';
383 $this->_info[
'stratum'] =
'primary reference';
387 $this->_info[
'stratum'] =
'secondary reference';
398 $this->_info[
'rootdelay'] = $binary[
'rootdelay'];
406 $this->_info[
'rootdispersion'] = $binary[
'rootdispersion'];
415 $this->_info[
'roundtrip'] = $binary[
'receivestamp'];
416 $this->_info[
'roundtrip'] -= $binary[
'originatestamp'];
417 $this->_info[
'roundtrip'] -= $binary[
'transmitstamp'];
418 $this->_info[
'roundtrip'] += $binary[
'clientreceived'];
419 $this->_info[
'roundtrip'] /= 2;
422 $this->_info[
'offset'] = $binary[
'receivestamp'];
423 $this->_info[
'offset'] -= $binary[
'originatestamp'];
424 $this->_info[
'offset'] += $binary[
'transmitstamp'];
425 $this->_info[
'offset'] -= $binary[
'clientreceived'];
426 $this->_info[
'offset'] /= 2;
427 $time = (
time() - $this->_info[
'offset']);
__construct($timeserver, $port=123)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
foreach( $_productCollection as $_product)() ?>" class $info