<?php
list($usec, $sec)=explode(” “,microtime());
$thisDate=sprintf(”%f”, ($usec+$sec));
$host=”$argv[1]”;
$port=”$argv[2]”;
if(!$host) {
die(”Usage: $0 host port [ dtg ]\n”);
}
$fp = fsockopen(”$host”, $port, $errno, $errstr, 30);
if (!$fp) {
print(”ping failed to host: $host:$port -
$errstr ($errno)\n”);
} else {
list($usec, $sec)=explode(” “,microtime());
$nextDate=sprintf(”%f”, ($usec+$sec));
if($argv[3]) {
printf(”%d:%0.4f\n”,time(),$nextDate-$thisDate);
} else {
printf(”%0.4f\n”,$nextDate-$thisDate);
}
fclose($fp);
}
?>
July 6th, 2007 at 8:25 pm
[…] PHP Coding School ยป Ping host measured in microseconds (tags: ping measured microseconds PHP Coding School) Subscribe to techie blogs central by Email […]