You are here

function sess_read in Memcache API and Integration 6

Same name and namespace in other branches
  1. 5.2 session-memcache.inc \sess_read()
  2. 5.2 session-memcache-db.inc \sess_read()
  3. 5.2 session-memcache.db.inc \sess_read()
  4. 5 memcache-session.inc \sess_read()

File

./memcache-session.inc, line 31
User session handling functions.

Code

function sess_read($key) {
  global $user;

  // Write and Close handlers are called after destructing objects since PHP 5.0.5
  // Thus destructors can use sessions but session handler can't use objects.
  // So we are moving session closure before destructing objects.
  register_shutdown_function('session_write_close');

  // Handle the case of first time visitors and clients that don't store
  // cookies (eg. web crawlers).
  if (!isset($_COOKIE[session_name()])) {
    $user = drupal_anonymous_user();
    return '';
  }

  // Otherwise, if the session is still active, we have a record of the
  // client's session in memcache.
  $session = dmemcache_get($key, 'session');
  $user = sess_user_load($session);

  // Record whether this session contains data so that in sess_write() it can
  // be determined whether to skip a write.
  if ($user->session_data_present_at_load = !empty($session->session)) {

    // Set a global value for the original session value to be compared against
    // during sess_write().
    $GLOBALS['memcache_session_last_read'] = array(
      'sid' => $session->sid,
      'value' => $user->session,
    );
  }
  return $user->session;
}