function dmemcache_instance in Memcache API and Integration 6
Same name and namespace in other branches
- 7 dmemcache.inc \dmemcache_instance()
Return a new memcache instance.
3 calls to dmemcache_instance()
- dmemcache_object in ./
dmemcache.inc - Returns an Memcache object based on the bin requested. Note that there is nothing preventing developers from calling this function directly to get the Memcache object. Do this if you need functionality not provided by this API or if you need to use…
- memcache_enable in ./
memcache.install - Implements hook_enable().
- memcache_requirements in ./
memcache.install - Implements hook_requirements().
File
- ./
dmemcache.inc, line 1046
Code
function dmemcache_instance() {
static $error = FALSE;
$extension = dmemcache_extension();
if ($extension == 'Memcache') {
return new Memcache();
}
elseif ($extension == 'Memcached') {
$memcache = new Memcached();
$default_opts = array(
Memcached::OPT_COMPRESSION => FALSE,
Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
);
foreach ($default_opts as $key => $value) {
$memcache
->setOption($key, $value);
}
// See README.txt for setting custom Memcache options when using the
// memcached PECL extension.
$memconf = variable_get('memcache_options', array());
foreach ($memconf as $key => $value) {
$memcache
->setOption($key, $value);
}
if (($sasl_username = variable_get('memcache_sasl_username', '')) && ($sasl_password = variable_get('memcache_sasl_password', ''))) {
$memcache
->setSaslAuthData($sasl_username, $sasl_password);
}
return $memcache;
}
else {
if (!$error) {
register_shutdown_function('watchdog', 'memcache', 'You must enable the PHP <a href="http://php.net/manual/en/book.memcache.php">memcache</a> (recommended) or <a href="http://php.net/manual/en/book.memcached.php">memcached</a> extension to use memcache.inc.', array(), WATCHDOG_ERROR);
$error = TRUE;
}
}
return FALSE;
}