API16

JSessionStorageDatabase/gc

From Joomla! Documentation

< API16:JSessionStorageDatabase
Revision as of 21:04, 24 March 2017 by JoomlaWikiBot (talk | contribs) (preparing for archive only)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Garbage collect stale sessions from the SessionHandler backend.



Syntax[edit]

gc($lifetime=1440)
Parameter Name Default Value Description
$lifetime 1440 The maximum age of a session.

Returns[edit]

boolean True on success, false otherwise.

Defined in[edit]

libraries/joomla/session/storage/database.php

Importing[edit]

jimport( 'joomla.session.storage.database' );

Source Body[edit]

function gc($lifetime = 1440)
{
        // Get the database connection object and verify its connected.
        $db = &JFactory::getDbo();
        if (!$db->connected()) {
                return false;
        }

        // Determine the timestamp threshold with which to purge old sessions.
        $past = time() - $lifetime;

        // Remove expired sessions from the database.
        $db->setQuery(
                'DELETE FROM `#__session`' .
                ' WHERE `time` < '.(int) $past
        );
        return (boolean) $db->query();
}



Examples[edit]

Code Examples[edit]