Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Sntp.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/TimeSync/Protocol.php';
26 
36 {
42  protected $_port = 37;
43 
49  private $_delay;
50 
57  public function __construct($timeserver, $port)
58  {
59  $this->_timeserver = 'udp://' . $timeserver;
60  if ($port !== null) {
61  $this->_port = $port;
62  }
63  }
64 
70  protected function _prepare()
71  {
72  return "\n";
73  }
74 
80  protected function _read()
81  {
82  $result = fread($this->_socket, 49);
83  $this->_delay = (($this->_delay - time()) / 2);
84 
85  return $result;
86  }
87 
94  protected function _write($data)
95  {
96  $this->_connect();
97  $this->_delay = time();
98  fputs($this->_socket, $data);
99  }
100 
107  protected function _extract($result)
108  {
109  $dec = hexdec('7fffffff');
110  $time = abs(($dec - hexdec(bin2hex($result))) - $dec);
111  $time -= 2208988800;
112  // Socket delay
113  $time -= $this->_delay;
114 
115  $this->_info['offset'] = $this->_delay;
116 
117  return $time;
118  }
119 }
_extract($result)
Definition: Sntp.php:107
_write($data)
Definition: Sntp.php:94
__construct($timeserver, $port)
Definition: Sntp.php:57