Skip to content

Instantly share code, notes, and snippets.

@andronex
Created October 2, 2017 20:33
Show Gist options
  • Save andronex/cb3f5cfb4670e9820c9332da6158748a to your computer and use it in GitHub Desktop.
Save andronex/cb3f5cfb4670e9820c9332da6158748a to your computer and use it in GitHub Desktop.
Удаление старых сессий в таблице MODX посредством плагина, а не настройками PHP.
<?php
$rand = rand(1, 1000);
if ($rand === 1) {
$gcMaxlifetime = (integer) $modx->getOption('session_gc_maxlifetime', null, @ini_get('session.gc_maxlifetime'), true);
$access = time() - $gcMaxlifetime;
$modx->exec("
DELETE FROM {$modx->getTableName('modSession')} WHERE `access` < {$access};
OPTIMIZE TABLE {$modx->getTableName('modSession')};
");
$modx->log(modX::LOG_LEVEL_ERROR, 'clearOldSessions: old sessions have been removed.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment