public
Description: Tiny PHP+mySQL BitTorrent tracker
Homepage: http://soultcer.net/wiki/Code/nanotrack
Clone URL: git://github.com/soult/nanotrack.git
nanotrack / cron.php
100644 26 lines (18 sloc) 0.912 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
 
// Some starting stuff
header('Content-type: text/plain');
require('config.inc.php');
 
// In case of an error
function send_error($error = 'Fatal error') {
die('CRONJOB ERROR: ' . $error . "\n");
}
 
// Connect to mysql
$mysql_connection = mysql_connect($config['mysql']['host'], $config['mysql']['user'], $config['mysql']['password']) or send_error('DB connection failed');
unset($config['mysql']['password']);
mysql_select_db($config['mysql']['database'], $mysql_connection) or send_error('DB connection failed');
 
// Delete old entries
mysql_query('DELETE FROM ' . $config['mysql']['table'] . ' WHERE last_seen < (NOW() - ' . $config['interval'] . ')', $mysql_connection) or send_error('DB delete failed');
 
// Of course we're proud that we change so many rows
echo 'Purged ' . mysql_affected_rows($mysql_connection) . ' old database entries';
 
// Close the connection
mysql_close($mysql_connection);