Memcached
- Introduction
- Installing/Configuring
- Predefined Constants
- Expiration Times
- Callbacks
- Sessions support
- Memcached — The Memcached class
- Memcached::add — Add an item under a new key
- Memcached::addByKey — Add an item under a new key on a specific server
- Memcached::addServer — Add a server to the server pool
- Memcached::addServers — Add multiple servers to the server pool
- Memcached::append — Append data to an existing item
- Memcached::appendByKey — Append data to an existing item on a specific server
- Memcached::cas — Compare and swap an item
- Memcached::casByKey — Compare and swap an item on a specific server
- Memcached::__construct — Create a Memcached instance
- Memcached::decrement — Decrement numeric item's value
- Memcached::decrementByKey — Decrement numeric item's value, stored on a specific server
- Memcached::delete — Delete an item
- Memcached::deleteByKey — Delete an item from a specific server
- Memcached::deleteMulti — Delete multiple items
- Memcached::deleteMultiByKey — Delete multiple items from a specific server
- Memcached::fetch — Fetch the next result
- Memcached::fetchAll — Fetch all the remaining results
- Memcached::flush — Invalidate all items in the cache
- Memcached::get — Retrieve an item
- Memcached::getAllKeys — Gets the keys stored on all the servers
- Memcached::getByKey — Retrieve an item from a specific server
- Memcached::getDelayed — Request multiple items
- Memcached::getDelayedByKey — Request multiple items from a specific server
- Memcached::getMulti — Retrieve multiple items
- Memcached::getMultiByKey — Retrieve multiple items from a specific server
- Memcached::getOption — Retrieve a Memcached option value
- Memcached::getResultCode — Return the result code of the last operation
- Memcached::getResultMessage — Return the message describing the result of the last operation
- Memcached::getServerByKey — Map a key to a server
- Memcached::getServerList — Get the list of the servers in the pool
- Memcached::getStats — Get server pool statistics
- Memcached::getVersion — Get server pool version info
- Memcached::increment — Increment numeric item's value
- Memcached::incrementByKey — Increment numeric item's value, stored on a specific server
- Memcached::isPersistent — Check if a persitent connection to memcache is being used
- Memcached::isPristine — Check if the instance was recently created
- Memcached::prepend — Prepend data to an existing item
- Memcached::prependByKey — Prepend data to an existing item on a specific server
- Memcached::quit — Close any open connections
- Memcached::replace — Replace the item under an existing key
- Memcached::replaceByKey — Replace the item under an existing key on a specific server
- Memcached::resetServerList — Clears all servers from the server list
- Memcached::set — Store an item
- Memcached::setByKey — Store an item on a specific server
- Memcached::setMulti — Store multiple items
- Memcached::setMultiByKey — Store multiple items on a specific server
- Memcached::setOption — Set a Memcached option
- Memcached::setOptions — Set Memcached options
- Memcached::setSaslAuthData — Set the credentials to use for authentication
- Memcached::touch — Set a new expiration on an item
- Memcached::touchByKey — Set a new expiration on an item on a specific server
- MemcachedException — The MemcachedException class
- Constant hash database
- Клиентская библиотека работы с URL
- Event
- File Alteration Monitor
- FTP
- Gearman
- Net Gopher
- Gupnp
- Hyperwave API
- Облегчённый протокол доступа к каталогам (LDAP)
- Memcache
- Memcached
- mqseries
- Network
- RRDtool
- Simple Asynchronous Messaging
- SNMP
- Сокеты
- Secure Shell2
- Stomp Client
- Support Vector Machine
- Subversion
- TCP Wrappers
- Varnish
- YAZ
- YP/NIS
- ZMQ
Коментарии
For those confuse about the memcached extension and the memcache extension, the short story is that both of them are clients of memcached server, and the memcached extension offer more features than the memcache extension.
The module also supports SASL authentication, it just isn't documented sadly. You'll need to run the following code:
<?php
$m = new Memcached();
$m->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$m->setSaslAuthData("user-1", "pass");
?>
You need to enable the "memcached.use_sasl = 1" ini option for memcached in the php.ini file.
GOTCHA: Recently I was tasked with moving from PECL memcache to PECL memcached and ran into a major problem -- memcache and memcached serialize data differently, meaning that data written with one library can't necessarily be read with the other library.
For example, If you write an object or an array with memcache, it's interpreted as an integer by memcached. If you write it with memcached, it's interpreted as a string by memcache.
tl;dr - You can't safely switch between memcache and memcached without a either a cache flush or isolated cache environments.
<?php
$memcache = new Memcache;
$memcacheD = new Memcached;
$memcache->addServer($host);
$memcacheD->addServers($servers);
$checks = array(
123,
4542.32,
'a string',
true,
array(123, 'string'),
(object)array('key1' => 'value1'),
);
foreach ($checks as $i => $value) {
print "Checking WRITE with Memcache\n";
$key = 'cachetest' . $i;
$memcache->set($key, $value);
usleep(100);
$val = $memcache->get($key);
$valD = $memcacheD->get($key);
if ($val !== $valD) {
print "Not compatible!";
var_dump(compact('val', 'valD'));
}
print "Checking WRITE with MemcacheD\n";
$key = 'cachetest' . $i;
$memcacheD->set($key, $value);
usleep(100);
$val = $memcache->get($key);
$valD = $memcacheD->get($key);
if ($val !== $valD) {
print "Not compatible!";
var_dump(compact('val', 'valD'));
}
}
## Installing Memcached on Ubuntu
To install Memcached on Ubuntu, go to terminal and type the following commands −
$sudo apt-get update
$sudo apt-get install memcached
## Confirming Memcached Installation
To confirm if Memcached is installed or not, you need to run the command given below. This command shows that Memcached is running on the default port 11211.
$ps aux | grep memcached
To run Memcached server on a different port, execute the command given below. This command starts the server on the TCP port 11111 and listens on the UDP port 11111 as a daemon process.
$memcached -p 11111 -U 11111 -u user -d
You can run multiple instances of Memcached server through a single installation.