Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Session GC Cli #19548

Merged
merged 2 commits into from Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions cli/sessionGc.php
@@ -0,0 +1,56 @@
<?php
/**
* @package Joomla.Cli
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

/**
* This is a CRON script to delete expired session data which should be called from the command-line, not the
* web. For example something like:
* /usr/bin/php /path/to/site/cli/sessionGc.php
*/

// Initialize Joomla framework
const _JEXEC = 1;

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

/**
* Cron job to trash expired session data.
*
* @since __DEPLOY_VERSION__
*/
class SessionGc extends JApplicationCli
{
/**
* Entry point for the script
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function doExecute()
{
JFactory::getSession()->gc();
}
}

JApplicationCli::getInstance('SessionGc')->execute();
12 changes: 12 additions & 0 deletions libraries/src/Session/Session.php
Expand Up @@ -834,6 +834,18 @@ public function close()
$this->_state = 'inactive';
}

/**
* Delete expired session data
*
* @return boolean True on success, false otherwise.
*
* @since __DEPLOY_VERSION__
*/
public function gc()
{
return $this->_store->gc($this->getExpire());
}

/**
* Set the session handler
*
Expand Down