I am receing the following error, once i selected Memcache as the cache Handler

Call to undefined function variable_init()

This is the code that generates the error

// Memcache module's cache_get function requires variables to be loaded
		//if (isset($conf['authcache_handler']) && $conf['authcache_handler'] == 'memcache.inc' && $vars_exist = cache_get('variables', 'cache')) {
		//TODO D7: simg: not sure if cache_get(variables) still needed?
		if (variable_get('cache_class_cache_page', '') == 'MemCacheDrupal') {
			$conf = variable_init($conf);
		}

And this are the settins that i have in my settings.php


include_once('sites/all/modules/contrib/memcache/memcache.inc');
$conf['cache_inc_via_authcache'] = 'sites/all/modules/contrib/memcache/memcache.inc';
$conf['cache_backends'][] = 'sites/all/modules/contrib/memcache/memcache.inc';
$conf['cache_backends'][] = 'sites/all/modules/contrib/authcache/authcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
#$conf['cache_class_cache_block'] = 'MemCacheDrupal';
$conf['cache_class_cache_page'] = 'MemCacheDrupal';



#$conf['session_inc'] =  'sites/all/modules/contrib/memcache/memcache-session.inc';
$conf['memcache_servers'] = array(
  'localhost:11211' => 'default',
  'localhost:11211' => 'filter',
  'localhost:11211' => 'menu',
  'localhost:11211' => 'block',
  'localhost:11211' => 'page',
  'localhost:11211' => 'users',
  'localhost:11211' => 'session',

);
$conf['memcache_bins'] = array(
  'cache' => 'default',
  'cache_filter' => 'filter',
  'cache_menu' => 'menu',
  'cache_page' => 'page',
  'cache_block' => 'block',
  'users' => 'users',
  'session' => 'session',
);

$conf['memcache_options'] = array(
  Memcached::OPT_COMPRESSION => FALSE,
  Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
);

Comments

simg’s picture

If you change that section of code to:

if (variable_get('cache_class_cache_page', '') == 'MemCacheDrupal') {
   $conf = variable_initialize($conf);
}

that should fix the undefined function error.

Note: I'm guessing you're probably (evidently) the first person to attempt to use the D7 version of authcache with memcache. ( I use filecache ). If you find / report any errors, you should get a pretty good response / fix time :)

sirviejo’s picture

Thanks for your quick response simg, that bypass the error.

Once i did that i receive another undefined function error saying that db_query is not defined.
And that is because the DRUPAL_BOOTSTRAP_PAGE_CACHE is the second phase and DRUPAL_BOOTSTRAP_DATABASE is the third.

That is why, i think it's incorrect to call any query depending function inside the DRUPAL_BOOTSTRAP_PAGE_CACHE phase.

simg’s picture

what is the exact error message (ie file name & line number ) ?

I'm not aware of any reason why authcache would try and call db_query for the exact reason you mention.

sirviejo’s picture

whe you receive a cache miss in the variable_initialize (first time you render the page befor caching), you will need to proceed with variable rebuild. This force you to need the database access.
Please let me know if i am making a mistake here.

Regards.

function variable_initialize($conf = array()) {
  // NOTE: caching the variables improves performance by 20% when serving
  // cached pages.
  if ($cached = cache_get('variables', 'cache_bootstrap')) {
    $variables = $cached->data;
  }
  else {
    // Cache miss. Avoid a stampede.
    $name = 'variable_init';
    if (!lock_acquire($name, 1)) {
      // Another request is building the variable cache.
      // Wait, then re-run this function.
      lock_wait($name);
      return variable_initialize($conf);
    }
    else {
      // Proceed with variable rebuild.
      $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
      cache_set('variables', $variables, 'cache_bootstrap');
      lock_release($name);
    }
  }

  foreach ($conf as $name => $value) {
    $variables[$name] = $value;
  }

  return $variables;
}
simg’s picture

oh, that's a shame. bootstrapping the database is something of an overhead which means the memcache option will be slower than it otherwise could be (it might be possible to optimise this in future).

for now, could you try modifying the lines in authcache.inc 65 - 69 to look like the following:

   // Connect to database if default database cache hander is selected
   if ($conf['authcache_is_db'] || variable_get('cache_class_cache_page', '') == 'MemCacheDrupal') {
      require_once DRUPAL_ROOT . '/includes/database/database.inc';
      db_set_active();
   }

Or, just download the latest dev version as it now contains the above code.

I suspect you'll get significantly better performance right now using FileCache (which was already somewhat faster than MemCache)

sirviejo’s picture

yes if i apply this change the module starts working.Anyways i do not get why only for using memcached the database is required (it should not!)

simg’s picture

Status: Active » Closed (fixed)

>why only for using memcached the database is required (it should not!)

because the memcache code apparently calls variable_initialize and it's variable_initialize which requires database access :/

edit: wasn't intending to be rude by closing this issue, just trying to keep the issue queue under control :)