Skip to content

Instantly share code, notes, and snippets.

@matdave
Last active November 10, 2025 22:44
Show Gist options
  • Select an option

  • Save matdave/7fe805a5bc578d5b182476966f739bb2 to your computer and use it in GitHub Desktop.

Select an option

Save matdave/7fe805a5bc578d5b182476966f739bb2 to your computer and use it in GitHub Desktop.
MODX GC Handler
<?php
/**
* MODX 2.x Cron Job
* Run: * * * * * php /www/2x.gc.php
**/
$tstart= microtime(true);
@include(dirname(__FILE__) . '/config.core.php');
if (!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', dirname(__FILE__) . '/core/');
if (!@include_once (MODX_CORE_PATH . "model/modx/modx.class.php")) {
die();
}
if (!@include_once (MODX_CORE_PATH . "model/modx/modsessionhandler.class.php")) {
die();
}
$modx= new modX();
$modx->startTime= $tstart;
$modx->initialize();
session_gc();
<?php
/**
* MODX 3.x Cron Job
* Run: * * * * * php /www/3x.gc.php
**/
$tstart = microtime(true);
define('MODX_API_MODE', true);
@include(dirname(__FILE__) . '/config.core.php');
if (!@require_once (MODX_CORE_PATH . "vendor/autoload.php")) {
exit();
}
ob_start();
$modx = new \MODX\Revolution\modX();
if (!is_object($modx) || !($modx instanceof \MODX\Revolution\modX)) {
ob_get_level() && @ob_end_flush();
exit();
}
$modx->startTime= $tstart;
$modx->initialize();
session_gc();
<?php
/**
* Plugin: gcKeepAlive
* Event: OnMODXInit
**/
@ini_set('session.gc_probability', '0');
if (empty($_SESSION)) return;
$_SESSION['gc_keep_alive'] = time();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment