Skip to content

Scheduler task com_plugins.task.sessiongc does not clean up sessions when executed via CLI (cron) #45637

Open
@jjnxpct

Description

@jjnxpct

Steps to reproduce the issue

  1. Set up a Joomla 5.x site with session handler set to "database"
  2. Enable the "System - Session Garbage Collector" plugin
  3. Schedule the com_plugins.task.sessiongc task using Joomla Scheduler
  4. Set the task to run daily via CLI using:
    php cli/joomla.php scheduler:run --all
  5. Let the session table grow over time with inactive sessions
  6. Check the number of records in the #__session table
  7. Now manually execute the same task via the Joomla backend (Scheduler > Tasks > Execute now)
  8. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions