the point is, i have tried with pinging the server but, pinging is not the right solution. it needs to scan several ports before it displays the on- or off-line message. One ping is not suitable because when the server lags or in other way doesn't pong the message will display offline while it isn't.
this is how i did it:
<?php
$portarray=array(8888,7777,6666,9999);
if(!$port) {
for($i=0;$i<count($portarray) AND $status!='online';$i++) {
$sock = fsockopen($host, $portarray[$i], &$num, &$error, 1);
if(!$sock) {
$status = "offline";
@fclose ($sock);
} else {
$status = "online";
@fclose ($sock);
}
}
} else {
$sock = fsockopen($host, $port, &$num, &$error, 100);
if(!$sock) {
$status = "offline";
@fclose ($sock);
} else {
$status = "online";
@fclose ($sock);
}
}
if($status=="online") {
echo "online";
} elseif($status=="offline") {
echo "offline";
}
?>
the page posts the dns and port to this file and generates the output, but as you can see.. it displays offline when the server doesn't respond or gives an error. i need it to scan all ports several times before.