Open
Description
Steps to reproduce the issue
- Set up a Joomla 5.x site with session handler set to "database"
- Enable the "System - Session Garbage Collector" plugin
- Schedule the
com_plugins.task.sessiongc
task using Joomla Scheduler - Set the task to run daily via CLI using:
php cli/joomla.php scheduler:run --all
- Let the session table grow over time with inactive sessions
- Check the number of records in the
#__session
table - Now manually execute the same task via the Joomla backend (Scheduler > Tasks > Execute now)
- Check the
#__session
table again
Expected result
Expired session records (older than the configured lifetime) are removed from the #__session
table both when:
- The task is executed via the backend
- The task is executed via the CLI (cron)
Actual result
- When executed via the backend, the task successfully removes expired sessions.
- When executed via CLI, the task is marked as "Completed" in the execution log, but expired session records remain in the database — the session cleanup does not occur.
System information (as much as possible)
- Joomla version: 5.x (tested on 5.0.3 and 5.1.0)
- PHP version: 8.2
- Session handler:
database
- CLI command:
php cli/joomla.php scheduler:run --all
Additional comments
It appears that the session cleanup (gc()
) relies on an active session handler context, which is not properly initialized in CLI mode. This causes Factory::getSession()->getHandler()->gc()
to have no effect during CLI runs.
The issue is not configuration-related: the same task, with no changes, works as expected via the backend.
Please consider:
- Initializing the session handler explicitly in this context
- Or falling back to direct database cleanup when session handler is not active in CLI
This issue affects Joomla administrators relying on the Scheduler system as a unified automation method.