_timeserver = 'udp://' . $timeserver; if ($port !== null) { $this->_port = $port; } } /** * Prepares the data that will be send to the timeserver * * @return array */ protected function _prepare() { return "\n"; } /** * Reads the data returned from the timeserver * * @return string */ protected function _read() { $result = fread($this->_socket, 49); $this->_delay = (($this->_delay - time()) / 2); return $result; } /** * Writes data to to the timeserver * * @param string $data Data to write to the timeserver * @return void */ protected function _write($data) { $this->_connect(); $this->_delay = time(); fputs($this->_socket, $data); } /** * Extracts the data returned from the timeserver * * @param string $result Data to extract * @return integer */ protected function _extract($result) { $dec = hexdec('7fffffff'); $time = abs(($dec - hexdec(bin2hex($result))) - $dec); $time -= 2208988800; // Socket delay $time -= $this->_delay; $this->_info['offset'] = $this->_delay; return $time; } }