ntp.org<\/a> podemos encontrar toda la informaci\u00f3n.<\/p>\n\n\n\nPara poder consultar la hora mediante NTP en PHP no existe ninguna librer\u00eda, por lo que hay que recurrir a clases o funciones. Mirando por aqu\u00ed y por all\u00e1 lo que he visto no funcionaba, as\u00ed que he creado la siguiente funci\u00f3n:<\/p>\n\n\n\n
function ntp_time ($host) {\n $msg = hex2bin('e30004fa000100000001000000000000000000000000000000000000000000000000000000000000');\n $data = false;\n if ($sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) {\n if (@socket_connect($sock, $host, 123)) {\n list($xmt['time2'], $xmt['time1']) = explode(' ', microtime());\n $xmt['time1'] += 2208988800;\n $xmt['time2'] *= 4294967296;\n $msg .= pack('N*', $xmt['time1'], $xmt['time2']);\n if (@socket_write($sock, $msg)) {\n if ($recv = @socket_read($sock, 48)) {\n $data = unpack('H2ntp.flags\/C1ntp.stratum\/C1ntp.ppoll\/c1ntp.precision\/N1ntp.rootdelay\/N1ntp.rootdispersion\/H8ntp.refid\/N2ntp.reftime\/N2ntp.org\/N2ntp.rec\/N2ntp.xmt', $recv);\n $data['hex'] = bin2hex($recv);\n $data['ntp.rootdelay'] = $data['ntp.rootdelay'] \/ pow(2, 16);\n $data['ntp.rootdispersion'] = $data['ntp.rootdispersion'] \/ pow(2, 16);\n $data['ntp.refid'] = implode('.', unpack('C*', hex2bin($data['ntp.refid'])));\n $data['ntp.reftime1'] = sprintf('%u', $data['ntp.reftime1']) - 2208988800;\n $data['ntp.reftime2'] = floor(1000000 * (sprintf('%u', $data['ntp.reftime2']) \/ pow(2, 32))) \/ 1000000;\n $data['ntp.org1'] = sprintf('%u', $data['ntp.org1']) - 2208988800;\n $data['ntp.org2'] = floor(1000000 * (sprintf('%u', $data['ntp.org2']) \/ pow(2, 32))) \/ 1000000;\n $data['ntp.rec1'] = sprintf('%u', $data['ntp.rec1']) - 2208988800;\n $data['ntp.rec2'] = floor(1000000 * (sprintf('%u', $data['ntp.rec2']) \/ pow(2, 32))) \/ 1000000;\n $data['ntp.xmt1'] = sprintf('%u', $data['ntp.xmt1']) - 2208988800;\n $data['ntp.xmt2'] = floor(1000000 * (sprintf('%u', $data['ntp.xmt2']) \/ pow(2, 32))) \/ 1000000;\n }\n }\n }\n }\n\n if (!empty($sock)) socket_close($sock);\n\n if ($data === false) {\n $err_nbr = socket_last_error();\n if (!empty($sock)) $err_nbr = socket_last_error($sock);\n $err_msg = socket_strerror($err_nbr);\n echo $err_nbr, ' - ', $err_msg, \"n\";\n }\n\n return $data;\n}<\/pre>\n","_es_post_name":"ntp-consultar-la-hora","_es_post_excerpt":"","_es_post_title":"NTP: Consultar la hora","_en_post_content":"","_en_post_name":"","_en_post_excerpt":"","_en_post_title":"","edit_language":"en","footnotes":""},"categories":[5,3],"tags":[16,6],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-php","category-tips","tag-ntp","tag-php"],"ninja_gutenberg_blocks_featured_media_urls":{"thumbnail":"","ninja_gutenberg_blocks_landscape_large":"","ninja_gutenberg_blocks_portrait_large":"","ninja_gutenberg_blocks_square_large":"","ninja_gutenberg_blocks_landscape":"","ninja_gutenberg_blocks_portrait":"","ninja_gutenberg_blocks_square":"","full":""},"_links":{"self":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":26,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":1848,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/57\/revisions\/1848"}],"wp:attachment":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}