In this
Post we learn to ping host and check connectivity between hosts in network.
Ping is usually used to check then connectivity between two host and got
strangth of connection.Ordinary, its sysntex is PING [Host name or IPAddress]
in command prompt.
Here we will not use any additional
plugins.
Its simply define function
`getconnection` with argument `$domain` in any class.
//Ping Host using php
function getconnection($domain){
$starttime =
microtime(true);
$file
= fsockopen ($domain, 80, $errno, $errstr, 10);
$stoptime = microtime(true);
$status = 0;
if (!$file) $status = -1; // Site is down
else {
fclose($file);
$status =
($stoptime - $starttime) * 1000;
$status =
floor($status);
}
return $status;
}
Index.php
<?php
$domain = 'www.google.com';
$ping =
getconnection($domain);
echo $domain . ' - ' .
$ping;
?>
To Download Project Source click here
0 comments:
Post a Comment