Skip to content

Instantly share code, notes, and snippets.

@Sentinel-7
Sentinel-7 / delete_old_sessions.php
Created March 31, 2021 07:23 — forked from andronex/delete_old_sessions.php
Удаление старых сессий в таблице MODX посредством плагина, а не настройками PHP.
<?php
/**
на событие OnMODXInit
*/
$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};