API16:JSessionStorageDatabase/gc
From Joomla! Documentation
Description
Garbage collect stale sessions from the SessionHandler backend.
Syntax
gc($lifetime=1440)
| Parameter Name | Default Value | Description |
|---|---|---|
| $lifetime | 1440 | The maximum age of a session. |
Returns
boolean True on success, false otherwise.
Defined in
libraries/joomla/session/storage/database.php
Importing
jimport( 'joomla.session.storage.database' );
Source Body
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
Code Examples