Created
October 2, 2017 20:33
-
-
Save andronex/cb3f5cfb4670e9820c9332da6158748a to your computer and use it in GitHub Desktop.
Удаление старых сессий в таблице MODX посредством плагина, а не настройками PHP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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