You are here

memcache.module in Memcache API and Integration 5.2

Same filename and directory in other branches
  1. 5 memcache.module
  2. 6 memcache.module
  3. 7 memcache.module

File

memcache.module
View source
<?php

function memcache_init() {
  if (strstr($_SERVER['PHP_SELF'], 'update.php') || strstr($_GET['q'], 'autocomplete')) {

    // update.php relies on standard error handler
  }
  else {
    register_shutdown_function('memcache_shutdown');
  }
}
function memcache_perm() {
  return array(
    'access memcache statistics',
  );
}

/**
 * See memcache_init() which registers this function as a shutdown function.
 * Displays memcache stats in the footer.
 */
function memcache_shutdown() {
  global $user, $_memcache_statistics;
  $output = '';

  // Try not to break non html pages.
  if (function_exists('drupal_get_headers')) {
    $headers = drupal_get_headers();
    if (strstr($headers, 'xml') || strstr($headers, 'javascript') || strstr($headers, 'plain')) {
      return;
    }
  }
  if (user_access('access memcache statistics')) {
    drupal_add_js(drupal_get_path('module', 'memcache') . '/memcache.js');
    $stats = array();
    foreach ($_memcache_statistics as $stat => $val) {
      $stats[] = "<strong>{$stat}:</strong> " . theme('item_list', $val);
    }
    if (!empty($stats)) {
      $output = theme('item_list', $stats);

      // this makes sure all of the HTML is within the <body> even though this <script> is outside it
      print '<div id="memcache-devel"><h2>' . t('Memcache statistics') . '</h2>' . $output . '</div>';
    }
  }
}

Functions

Namesort descending Description
memcache_init
memcache_perm
memcache_shutdown See memcache_init() which registers this function as a shutdown function. Displays memcache stats in the footer.