You are here

function session_api_session_api_cleanup in Session API 5

Implementation of hook_session_api_cleanup().

A self implementation of the Session API cleanup hook. Generally called from session_api_cron().

Parameters

string $op: The operation the function perform.

  • run - perform the cleanup
  • info - provide information(in the form of a keyed array) of the title and description of the cleanup.

Return value

Varies with $op.

  • run - NULL
  • info - a keyed array containing title and description

File

./session_api.module, line 103
The Session API module provides a quick interface for storing information in the session.

Code

function session_api_session_api_cleanup($op = 'run') {
  switch ($op) {
    case 'info':
      return array(
        'title' => t('Clear expired <strong>Session API</strong> sessions'),
        'description' => t('Clear out old <strong>Session API</strong> IDs for which the corresponding <a href="!php">PHP session</a> no longer exists. <br /><strong>Important</strong>: This option must be checked for any of the subsequent cleanup processes to work. Unchecking this will disable any removal of expired session data.', array(
          '!php' => url('http://php.net/manual/en/book.session.php'),
        )),
      );
    case 'run':
    default:

      // fetch list of outdated sids
      $result = db_query("SELECT sap.sid FROM {session_api} sap LEFT JOIN {sessions} s ON (sap.session_id = s.sid) WHERE s.sid IS NULL");
      while ($session = db_fetch_object($result)) {

        // remove the session api id
        db_query("DELETE FROM {session_api} WHERE sid = %d", $session->sid);
      }
  }
}