51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
namespace YTKNS;
|
|
|
|
if(!defined('YTKNS_SEM_NAME'))
|
|
define('YTKNS_SEM_NAME', 'b');
|
|
if(!defined('YTKNS_SFM_PATH'))
|
|
define('YTKNS_SFM_PATH', sys_get_temp_dir() . DIRECTORY_SEPARATOR . '{04884071-d334-4388-947a-4fd8c4d4f4ea}');
|
|
|
|
if(!is_file(YTKNS_SFM_PATH))
|
|
touch(YTKNS_SFM_PATH);
|
|
|
|
$ftok = ftok(YTKNS_SFM_PATH, YTKNS_SEM_NAME);
|
|
$semaphore = sem_get($ftok, 1);
|
|
if(!sem_acquire($semaphore))
|
|
die('Failed to acquire semaphore.' . PHP_EOL);
|
|
|
|
try {
|
|
require_once __DIR__ . '/startup.php';
|
|
|
|
// Prevent running cron script during maintenance
|
|
if(!YTKNS_MAINTENANCE) {
|
|
// Destroy old sessions
|
|
UserSession::purge();
|
|
|
|
// Resynchronise use counts
|
|
Upload::resync(EFFECT_UPLOADS);
|
|
|
|
// Destroy orphaned uploads
|
|
Upload::purgeOrphans();
|
|
|
|
// Get task queue
|
|
$taskQueue = ZoneTask::queue();
|
|
|
|
// Plow through tasks
|
|
// TODO: make task functions modular
|
|
while($task = array_shift($taskQueue)) {
|
|
if(!isset($zoneInfo) || $zoneInfo->getId() !== $task->getZoneId())
|
|
$zoneInfo = $task->getZone();
|
|
|
|
switch($task->getName()) {
|
|
case 'screenshot':
|
|
$zoneInfo->takeScreenshot();
|
|
break;
|
|
}
|
|
|
|
$task->delete();
|
|
}
|
|
}
|
|
} finally {
|
|
sem_release($semaphore);
|
|
}
|