try
{
$socket = fsockopen($host,$port,$e_number,$e_string,$timeout);
fwrite($socket,str_repeat(" ",8));
}catch(Exception $e)
{
//Not a valid domain more than likly!
return false;
}
<?php
error_reporting(0);
function testurl($host) {
$page = file_get_contents($host);
if (false === $page)
{
return false;
}
else
{
return true;
}
}
if (testurl('http://google.com'))
{
echo 'google is awake';
}
else
{
echo 'google is not awake';
}
?>
function check_host($host)
{
if(false !== ($context = get_headers($host,1)))
{
/*
$context will look like so
Array
(
[0] => HTTP/1.1 200 OK
[Date] => Sat, 29 May 2004 12:28:14 GMT
[Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux)
[Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
[ETag] => "3f80f-1b6-3e1cb03b"
[Accept-Ranges] => bytes
[Content-Length] => 438
[Connection] => close
[Content-Type] => text/html
)
*/
return true;
}
}