Ok so here is the problem. The other week my host ran an automatic update as they often do on our server. Well somehow the update updated the php.ini file and removed an extension that we needed to be loaded at all times. All that was required to fix it was add in the extension=thingy.so but since nobody at my office looks at our site over the weekend we had no idea it went down so basically we lost a weekends worth of business and thats never good. Since our host does not keep records of everything that was changed or even when updates are run (silly, huh?) they wouldn't take responsibility.
So what I want to do is setup a cron job to check to make sure the site is still up and running and if not fire out text messages and emails to me and my boss. Now I originally thought about an md5 of some page and check every hour if the md5 of the index page is the same as it should be. This would work but the problem is that we have dynamic content on the site which would make the md5 change even though the site is running normally. Another option I though about was just stripping out the dynamic content and get the md5 of the (mostly) static content. This would make sense but then I don't know for sure if all parts of the website are running smoothly (such as the forums) since its content is dynamic.
So does anyone have any better suggestions?
Check if site is up and running
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
If something is disabled such as a function or class you're going to get an E_FATAL unless, I believe, you have defined a function with set_error_handler() and are using a version of PHP with E_RECOVERABLE defined. You may want to consider writing unit tests of the PHP configuration, tests that sessions work, functions exists, configuration values are set correct etc. I have this function to test if my sessions are working:I don't run this in a cron, but I could. Also be wary about sending emails, you could end mail bombing yourself and it's possible the thing responsible for sending the mails could break, you want to use the simplest possible systems for these things. Standard error logs with another system responsible for reading them back to you would probably be good.
Code: Select all
function testSession()
{
// This test works by creating a session with one script storing a number
// and reading back the number + 13 from a second, separate script
$rand = mt_rand(1, 10000);
$h = curl_init("http://localhost/sessionIn.php?number=$rand");
curl_setopt_array($h, array(
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
));
$headers = headerMakeKeys(curl_exec($h));
curl_close($h);
if (attest((int)$headers['.'], $rand)) {
return false;
}
$cookie = $headers['Set-Cookie'];
$cookie = substr($cookie, 0, strpos($cookie, ';'));
$h = curl_init('http://localhost/sessionOut.php');
curl_setopt_array($h, array(
CURLOLT_HTTPHEADER => array("Cookie: $cookie",),
CURLOPT_RETURNTRANSFER => true,
));
return attest((int)curl_exec($h), $random + 13);
}
function headerMakeKeys($headers)
{
$headers = explode("\n", $headers);
static $keyValueSeparator = ':';
$out = array('.' => array_pop($headers)); // value
foreach (array_filter($headers) as $header) {
$separatorPos = strpos($keyValueSeparator, $header);
if ($separatorPos === null) {
$out[] = $header;
continue;
}
$out[substr($header, 0, $separatorPos + 1)] = trim(substr($header, $separatorPos));
}
return $out;
}- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
I think the easiest way to check from a cron job would be to have your main page output a timestamp every time it's created & hide it in comments. Then your cronjob can file_get_contents() the page, read the timestamp & if it's not current, freak out.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.