note 72673 rejected from function.fsockopen by nicobn
| From: | nicobn@php.net | Date: | Sun, 08 Jul 2007 17:27:52 +0000 |
| Subject: | note 72673 rejected from function.fsockopen by nicobn | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128305@lists.php.net to get a copy of this message | ||
Note Submitter: ryan1_00 at hotmail dot com
----
Function to "ping" a server.
// check if a server is up by connecting to a port
function chkServer($host, $port)
{
$hostip = gethostbyname($host); // resloves IP from Hostname returns hostname on failure
if ($hostip == $host) // if the IP is not resloved
{
echo "Server is down or does not exist";
}
else
{
if (!$x = fsockopen($hostip, $port, $errno, $errstr, 5)) // attempt to connect
{
echo "Server is down";
}
else
{
echo "Server is up";
if ($x)
{
fclose($x); //close connection (i dont know if this is needed or not).
}
}
}
}