I have written a script to monitor network status by calculating the time take to connect to port 80. I get the microtime() before and after the connection and then subtract the first from the last to get the difference - sounds simple? Well, frequently I get a negative number, suggesting that the time after connection existed before the prior to connection. Problems with the Time Space Continuum I feel...
<pre>
// --GETMICROTIME-- format time into seconds and milliseconds
function getmicrotime()
{
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
return ($mtime);
}
$opentime=getmicrotime();
$con=fsockopen('www.lastoption.com',80);
if (!$con)
{
print("****");
exit;
}
$connecttime=getmicrotime();
$diff=$connecttime-$opentime;
print($diff);
print("<br>before: $opentime<br> after: $connecttime");
<pre>
Gave me:
-0.55576694011688
before: 985363794.59342
after: 985363794.03765
Any Ideas?