? Pending

User tests: Successful: Unsuccessful:

avatar joomdonation
joomdonation
3 Feb 2018

Pull Request for Issue # .

Summary of Changes

Since Joomla 3.8.4, if you use Database Session Handler, session data won't be deleted on page loads like in older version of Joomla anymore, it now relies on PHP session data garbage collection proces to delete session data and could cause session data stay longer in database than expected. On some hostings, session.gc_probability http://php.net/manual/en/session.configuration.php#ini.session.gc-probability even has value set to 0, mean session data won't be deleted at all.

This PR implements a simple CLI script so that you can setup cron job to clean up session data if needed. It will be more reliable than rely on session data garbage collection and for high traffic website, you will get big performance improvement (set session.gc_probability to 0 and setup cron job to delete session data- see #19146 for a use case)

Testing Instructions

  1. Go to System - Global Configuration, look at System tab, set Session Handler to Database, Session Lifetime to 1 minute

  2. Access to frontend of your site so that a new record will be inserted into #__session table

  3. Access to your site database via PHPMyadmin, look at #__session, you should see some records

  4. Wait for about one minute

  5. Run this CLI script. I don't know about Linux, but on Windows, I just need to run this command from Command Line php D:\www\joomla\cli\sessionGc.php (D:\www\joomla needs to be replaced with the path of your Joomla installation)

  6. Check #__session table again, you should see that the old records were deleted (maybe all records deleted)

Documentation Changes Required

Maybe we need to document this new feature if accepted

avatar joomdonation joomdonation - open - 3 Feb 2018
avatar joomdonation joomdonation - change - 3 Feb 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 3 Feb 2018
Category CLI Libraries
avatar joomdonation joomdonation - change - 3 Feb 2018
The description was changed
avatar joomdonation joomdonation - edited - 3 Feb 2018
avatar csthomas
csthomas - comment - 3 Feb 2018

Another way can be only:

	public function doExecute()
	{
		$config = JFactory::getConfig();

		$expire = $config->get('lifetime');
		$expire = $expire ? $expire * 60 : 900;

		$handler = $config->get('session_handler', 'none');
		$options = array('expire' => $expire);

		$storage = JSessionStorage::getInstance($handler, $options);
		$storage->gc($expire);
	}
avatar mbabker
mbabker - comment - 3 Feb 2018

Honestly, direct calling the storage layer of the session should be avoided, that part of the API is typically an internal detail and in 4.0 you honestly don't have direct access to it (you have to go through a Joomla\Session\SessionInterface implementation, in the CMS that's Joomla\CMS\Session\Session to interact with sessions at any level unless you're using Reflection to get access to stuff you shouldn't). So what is there now is fine.

avatar joomdonation joomdonation - change - 4 Feb 2018
Labels Added: ?
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 4 Feb 2018

@csthomas can you please mark your Test as successfully?

avatar csthomas
csthomas - comment - 4 Feb 2018

I have tested this item successfully on bb1bb93


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19548.

avatar csthomas csthomas - test_item - 4 Feb 2018 - Tested successfully
avatar joomdonation
joomdonation - comment - 6 Feb 2018

@mbabker Can this one go into 3.8.5? It could be useful for site using Database Handler running on host has session.gc-probability set to 0, they can use this core cli instead of writing the code themself

avatar brianteeman
brianteeman - comment - 6 Feb 2018

It's a new feature so semantic versioning says 3.9

avatar joomdonation
joomdonation - comment - 6 Feb 2018

@brianteeman It is an additional feature to provide a way to fix the change we made in 3.8.4, so It could go into 3.8.5 if it is possible

avatar mbabker
mbabker - comment - 6 Feb 2018

3.8.5 has a specific purpose and is not getting crammed full of miscellaneous stuff.

avatar mbabker
mbabker - comment - 14 Feb 2018

No longer required pending acceptance of #19678

avatar mbabker
mbabker - comment - 14 Feb 2018

Changed my mind. Merging this. We need a plugin to do session gc as pointed out in #19585 and this PR adds the API to do it. SemVer be damned right now I guess.

avatar mbabker mbabker - change - 14 Feb 2018
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2018-02-14 15:28:06
Closed_By mbabker
avatar mbabker mbabker - close - 14 Feb 2018
avatar mbabker mbabker - merge - 14 Feb 2018

Add a Comment

Login with GitHub to post a comment