1
0
Fork 0

Prevent script from executing if it is currently running.

This commit is contained in:
Andrew Tomaka 2011-10-15 07:16:54 -04:00
parent 590a77cd45
commit a4cbd44400
1 changed files with 26 additions and 0 deletions

View File

@ -4,14 +4,22 @@
// * * * * * php cronjobs/index_data.php >/dev/null 2>&1
// Collect data from various services and store locally for later display.
//***************************************************************************//
$startTime = time();
$interruptedExecution = false;
register_shutdown_function('shutdown');
clearstatcache();
if(in_array($_SERVER['SERVER_NAME'],array('localhost','a.io'))) {
$CACHE_FILE = '../data/cache.txt';
$DATA_FILE = '../data/index.txt';
$LOCK_FILE = getcwd() . '/../data/whoisandrew.lock';
} else {
chdir('/home/atomaka/data');
$CACHE_FILE = 'cache.txt';
$DATA_FILE = 'index.txt';
// path changes in the shutdown() function so we need the full path
$LOCK_FILE = '/home/atomaka/data/whoisandrew.lock';
}
$dataSources = array(
@ -25,6 +33,15 @@ $dataSources = array(
'wow' => 43200,
);
if(!file_exists($LOCK_FILE)) {
touch($LOCK_FILE);
} else {
$interruptedExecution = true;
exit();
}
while(true) { }
if(file_exists($CACHE_FILE)) {
$cacheData = json_decode(file_get_contents($CACHE_FILE),true);
} else {
@ -304,4 +321,13 @@ function progression_sort($a, $b) {
return $a['progression'] < $b['progression'];
}
function shutdown() {
global $interruptedExecution, $LOCK_FILE, $startTime;
if(!$interruptedExecution) {
unlink($LOCK_FILE);
}
$completionTime = time() - $startTime;
}
?>