![]() |
PHP pack() troubles (I will PayPal for expert help)
'm looking for someone who is very familar with PHP
pack and unpack() magic for help with a script I'm working on. I wrote a Perl script to query an ntp (time) server and I need to port it to PHP. I've got most of it, but using the named parameters with unpack() is foreign to me and I've got some long, complicated unpacking to do. Looking at the docs and at my code makes my head swim. Here's my original (working) Perl script: http://proxycheck.bettercgi.com:81/time.pl.txt Mostly ported to PHP, with a bit of work left: http://proxycheck.bettercgi.com:81/time.php.txt |
Those URLs should have been:
http://proxycheck.bettercgi.com:81/time_pl.txt and http://proxycheck.bettercgi.com:81/time_php.txt |
Why do you need to pack and unpack?
If you just want to query a time server this does it using port13 and port37. Thanks to google, Ralf at qrq.de and some modifications by me. function query_time_server ($timeserver, $socket) { $fp = fsockopen($timeserver,$socket,$err,$errstr,5); # parameters: server, socket, error code, error text, timeout if ($fp) { fputs($fp,"\n"); $timevalue = fread($fp,49); fclose($fp); } else { $timevalue = " "; } $ret = array(); $ret[] = $timevalue; $ret[] = $err; $ret[] = $errstr; return($ret); } $timestamp = time(); $datum = date("Y-m-d (D) H:i:s",$timestamp); echo "Current date and local time on this server is $datum \n"; $timeserver = "time-C.timefreq.bldrdoc.gov"; $timercvd = query_time_server($timeserver,37); if (!$timercvd[1]) { # if no error from query_time_server $timevalue = bin2hex ($timercvd[0]); $timevalue = abs (HexDec('7fffffff') - HexDec($timevalue) - HexDec('7fffffff')) ; $tmestamp = $timevalue - 2208988800; # convert to UNIX epoch time stamp $datum = date("Y-m-d (D) H:i:s",$tmestamp - date("Z",$tmestamp)); /* incl time zone offset */ $doy = (date("z",$tmestamp)+1); echo "Time check from time server ",$timeserver,". \n" ."The current date and universal time is ",$datum," UTC. \n" ."",$timevalue," seconds since 1900-01-01 00:00.00. \n" ."It is day ",$doy," of this year. \n" ."The unix epoch time stamp is $tmestamp. \n"; } else { echo "Unfortunately, the time server $timeserver could not be reached at this time. " ."$timercvd[1] $timercvd[2]. \n"; } $timercvd = query_time_server($timeserver,13); if (!$timercvd[1]) { $timevalue = $timercvd[0]; echo "Or if you prefer [",$timevalue,"]. \n"; } else { echo "Unfortunately, the time server $timeserver could not be reached at this time. " ."$timercvd[1] $timercvd[2]. \n"; } ?> |
Thanks. I had actually seen that but wanted to use
NTP rather than time or daytime protocols. Most time servers only support ntp now and allso the time formats for time and daytime and not well defined. |
All times are GMT -4. The time now is 04:29 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc