How to Monitor Website using PHP
Posted: Sun Nov 29, 2009 4:46 am
If you have many domain names, and/or pointers to domains, that you do not visit at least daily you may want this script. It will tell you if your sites are having issues. For example, what if someone hacked your registrar and pointed your domain name to another DNS (yes, this actually happened to me)? Or what if the zone files are borked at your webhost? Or what if there was a server issue (or a hacker) that deleted your files? Or what if you have a database driven site and the database is down? Doing a simple website ping on port 80 will not answer all these questions. Using this script will.
This is a simple script that can be executed to monitor a whole list of domains. The script tests for the presence of a character string on any specific page of your website. Run it at least every day.
The script requires a data file named domains.txt. That text file should contain one line per website page you want to monitor. Each line should have the url, the | character as a delimiter, then the search string. Example lines could be:
This is a simple script that can be executed to monitor a whole list of domains. The script tests for the presence of a character string on any specific page of your website. Run it at least every day.
The script requires a data file named domains.txt. That text file should contain one line per website page you want to monitor. Each line should have the url, the | character as a delimiter, then the search string. Example lines could be:
Code: Select all
tips-scripts.com|is a collection
otherdomain.com/directory/test.htm|content on that page
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Domain Verification</title>
<style type="text/css">
a { color: rgb(50,100,150); text-decoration: none; }
a:hover { color: rgb(150,100,50); }
</style>
</head>
<body>
<?php
$domainFile = "domains.txt";
$domainsArray = preg_replace("#\r\n?|\n#","",file($domainFile));
echo "<span style='font-weight: bold;'>Domain Validation</span><br />";
foreach ($domainsArray as $temp1Array) {
$temp2Array = explode("|",$temp1Array);
$url = $temp2Array[0];
$testString = $temp2Array[1];
$testFile = @file_get_contents("http://".$url);
if (strstr($testFile,$testString))
echo "<span style='color: green;'>? </span><a href='http://".$url."'>".$url."</a><br />";
else
echo "<span style='color: red;'>? </span><a href='http://".$url."'>".$url."</a><br />";
}
echo "Done.";
?>
</body>
</html>