You could use [man]fsock()[/man] to try to connect to a port (for example, 80 to check if a webserver is running). Maybe try something like this:
$fp = fsockopen ("www.example.com", 80, $errno, $errstr, 30);
if(!$fp)
{
echo "Web server is down";
}
else
echo "Web server is up";
}
fclose($fp);
Please note: I haven't tested this to see if it works. This is just an example.