That's a rather inefficient way of doing it. The simplest would be to just connect to the remote server:
Code:
<?php
$online = false;
if($f = fsockopen('svyt.com', 80)) {
$online = true;
fclose($f);
}
?>
However, this won't catch if the server is up but the site not functioning. You could use an HEAD request for that:
Code:
<?php
$online = false;
if($f = fsockopen('svyt.com', 80)) {
$request = <<<END
HEAD /proxy.html HTTP/1.1
Host: www.svyt.com
Connection: Close
END;
fwrite($f, $request);
$response = '';
while(!feof($f) && strpos($response, "\n") === false)
$response .= fread($f, 1);
$response = explode(' ', $response);
$response = $response[1];
if($reponse[0] < 4 && $reponse[0] > 1)
$online = true;
fclose($f);
}
?>
Bookmarks