2003-06-18 22:11:53 +00:00
|
|
|
#! /usr/local/bin/php -q
|
2003-02-28 22:39:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// watchdog script to ensure that the number of result records
|
|
|
|
// increases at least every X seconds (X = crontab period)
|
|
|
|
|
2003-03-06 19:53:32 +00:00
|
|
|
include_once("db.inc");
|
2003-02-28 22:39:36 +00:00
|
|
|
include_once("util.inc");
|
|
|
|
|
|
|
|
function fail($x) {
|
|
|
|
$f = fopen("error_log", "a");
|
|
|
|
if (!$f) return false;
|
|
|
|
fputs($f, "[".strftime("%T %D")."] ");
|
|
|
|
fputs($f, $x);
|
|
|
|
fclose($f);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function read_count_file() {
|
|
|
|
if (!file_exists("nresults")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$lines = file("nresults");
|
|
|
|
if (!$lines) return false;
|
2003-03-25 19:16:54 +00:00
|
|
|
return $lines;
|
2003-02-28 22:39:36 +00:00
|
|
|
}
|
|
|
|
|
2003-03-25 19:16:54 +00:00
|
|
|
function write_count_file($n,$m) {
|
2003-02-28 22:39:36 +00:00
|
|
|
$f = fopen("nresults", "w");
|
|
|
|
if (!$f) return false;
|
2003-06-14 20:03:08 +00:00
|
|
|
$x = sprintf("%d\n%d\n", $n, $m);
|
2003-02-28 22:39:36 +00:00
|
|
|
fwrite($f, $x);
|
|
|
|
fclose($f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-03-25 19:16:54 +00:00
|
|
|
function get_working_count_from_db() {
|
|
|
|
$result = mysql_query("select count(*) from result where server_state = 4");
|
|
|
|
if (!$result) return false;
|
|
|
|
$count = mysql_fetch_array($result);
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $count[0];
|
|
|
|
}
|
|
|
|
|
2003-02-28 22:39:36 +00:00
|
|
|
function get_count_from_db() {
|
|
|
|
$result = mysql_query("select count(*) from result");
|
|
|
|
if (!$result) return false;
|
|
|
|
$count = mysql_fetch_array($result);
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $count[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
$retval = db_init();
|
2003-03-06 19:53:32 +00:00
|
|
|
if ($retval != 0) {
|
|
|
|
fail("Can't open database\n");
|
2003-02-28 22:39:36 +00:00
|
|
|
}
|
|
|
|
$m = get_count_from_db();
|
|
|
|
if ($m == false) {
|
2003-03-06 19:53:32 +00:00
|
|
|
fail("Can't get result count from DB\n");
|
2003-02-28 22:39:36 +00:00
|
|
|
}
|
2003-03-25 19:16:54 +00:00
|
|
|
$p = get_working_count_from_db();
|
|
|
|
if ($p == false) {
|
|
|
|
fail("Can't get working result count from DB\n");
|
|
|
|
}
|
2003-02-28 22:39:36 +00:00
|
|
|
$n = read_count_file();
|
|
|
|
if ($n == false) {
|
2003-03-25 19:16:54 +00:00
|
|
|
write_count_file($m,$p);
|
2003-02-28 22:39:36 +00:00
|
|
|
exit();
|
|
|
|
}
|
2003-03-25 19:16:54 +00:00
|
|
|
if (trim($n[0]) == $m && trim($n[1]) == $p) {
|
2003-02-28 22:39:36 +00:00
|
|
|
fail("Result count hasn't changed\n");
|
|
|
|
}
|
2003-03-25 19:16:54 +00:00
|
|
|
write_count_file($m,$p);
|
2003-02-28 22:39:36 +00:00
|
|
|
|
|
|
|
?>
|