Hi,
I installed memcache on my development machine and I wanted to only try out memcache on the 'cache' bin. However, I found that I got thousands of these errors:
[08-May-2008 14:06:52] PHP Warning: Memcache::get() [<a href='function.Memcache-get'>function.Memcache-get</a>]: Failed to extract 'connection' variable from object in /path/to/drupal/sites/all/modules/cacherouter/engines/memcache.php on line 42
[08-May-2008 14:06:52] PHP Warning: Memcache::add() [<a href='function.Memcache-add'>function.Memcache-add</a>]: Failed to extract 'connection' variable from object in /path/to/drupal/sites/all/modules/cacherouter/engines/memcache.php on line 153
It took me a while to figure out but I finally found that the problem was in the construct function in memcache.php. Because the superclass construct() function is called near the end of the construct() function in memcache.php, $this->name is not yet set. As a result, then tries to see if $conf['cacherouter']['default']['server']. From the notes on the front page, it implies that the server parameter should be set to array - memcache see that, and cannot find anything to connect with (even if you did not set it, it will try to connect with localhost on port 11211; if you set memcached on another port, then this still goes on). Thus, nothing can get cached.
There are a few ways of going about on this - (a) check against $bin directly, (b) call the superclass construct() before going through setting the rest of the parameters, (c) assign $this->name = $bin. I opted for (a) in my code and I added a check that the bin is set or warnings would pop up in my error logs. My construct function for memcache.php currently looks as:
function __construct($bin) {
global $conf;
// Assign the servers on the following order: bin specific -> default specific -> localhost port 11211
if (isset($conf['cacherouter'][$bin]['server'])) {
$this->settings['servers'] = $conf['cacherouter'][$bin]['server'];
}
elseif (!isset($conf['cacherouter'][$bin]['server'])) {
if (isset($conf['cacherouter']['default']['server'])) {
$this->settings['servers'] = $conf['cacherouter']['default']['server'];
}
else {
$this->settings['servers'] = array('localhost:11211');
}
}
$this->settings['compress'] = isset($conf['cacherouter'][$bin]['compress']) ? MEMCACHE_COMPRESSED : 0;
$this->settings['shared'] = isset($conf['cacherouter'][$bin]['shared']) ?
$conf['cacherouter'][$bin]['shared'] : TRUE;
parent::__construct($bin);
$this->connect();
}
Comments
Comment #1
btmash commentedI should have mentioned this is also in the filecaching extension so that was changed to:
Comment #2
slantview commentedThank you. I'll get this in the next beta.
Comment #3
slantview commentedFixed in http://drupal.org/cvs?commit=118964 with (A)
Thanks.
Comment #4
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.