2023-04-08 21:06:28 +00:00
|
|
|
<?php
|
|
|
|
|
2023-08-01 14:53:14 +00:00
|
|
|
// Stop cleaner on cli running
|
|
|
|
$semaphore = sem_get(crc32('cli.yggo'), 1);
|
2023-04-08 21:06:28 +00:00
|
|
|
|
|
|
|
if (false === sem_acquire($semaphore, true)) {
|
|
|
|
|
2023-08-01 14:53:14 +00:00
|
|
|
echo 'cli.yggo process running in another thread.' . PHP_EOL;
|
2023-07-30 18:47:09 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2023-08-01 14:53:14 +00:00
|
|
|
// Lock multi-thread execution
|
|
|
|
$semaphore = sem_get(crc32('crontab.cleaner'), 1);
|
2023-07-30 18:47:09 +00:00
|
|
|
|
|
|
|
if (false === sem_acquire($semaphore, true)) {
|
|
|
|
|
2023-08-01 14:53:14 +00:00
|
|
|
echo 'process locked by another thread.' . PHP_EOL;
|
2023-04-08 21:06:28 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2023-08-03 12:25:38 +00:00
|
|
|
// Define variables
|
|
|
|
$timeStart = microtime(true);
|
2023-08-01 14:53:14 +00:00
|
|
|
|
2023-04-08 21:06:28 +00:00
|
|
|
// Load system dependencies
|
2023-06-30 11:38:29 +00:00
|
|
|
require_once(__DIR__ . '/../config/app.php');
|
|
|
|
require_once(__DIR__ . '/../library/mysql.php');
|
2023-04-08 21:06:28 +00:00
|
|
|
|
|
|
|
// Connect database
|
2023-08-05 16:39:49 +00:00
|
|
|
try {
|
|
|
|
|
|
|
|
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
|
|
|
|
|
|
|
|
} catch(Exception $e) {
|
|
|
|
|
|
|
|
var_dump($e);
|
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
2023-04-08 21:06:28 +00:00
|
|
|
|
2023-08-05 16:06:39 +00:00
|
|
|
// Reset banned hosts
|
|
|
|
$hostsBansRemoved = $db->resetBannedHostPages(time() - CLEAN_HOST_PAGE_BAN_SECONDS_OFFSET);
|
|
|
|
|
2023-08-03 12:25:38 +00:00
|
|
|
// Reset banned pages
|
2023-08-05 16:06:39 +00:00
|
|
|
$hostPagesBansRemoved = $db->resetBannedHosts(time() - CLEAN_HOST_BAN_SECONDS_OFFSET);
|
2023-06-13 13:51:16 +00:00
|
|
|
|
|
|
|
// Optimize tables
|
|
|
|
if (CLEAN_DB_TABLES_OPTIMIZATION) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2023-05-29 19:13:41 +00:00
|
|
|
$db->optimize();
|
2023-05-13 23:39:32 +00:00
|
|
|
|
2023-06-13 13:51:16 +00:00
|
|
|
} catch (Exception $e) {
|
2023-05-05 02:26:53 +00:00
|
|
|
|
2023-06-13 13:51:16 +00:00
|
|
|
var_dump($e);
|
|
|
|
}
|
2023-04-08 21:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Debug
|
2023-08-05 16:06:39 +00:00
|
|
|
echo 'Host bans removed: ' . $hostsBansRemoved . PHP_EOL;
|
2023-05-06 05:45:37 +00:00
|
|
|
echo 'Host page bans removed: ' . $hostPagesBansRemoved . PHP_EOL;
|
2023-05-08 05:27:21 +00:00
|
|
|
|
2023-08-03 12:25:38 +00:00
|
|
|
echo 'Total time: ' . microtime(true) - $timeStart . PHP_EOL . PHP_EOL;
|