Developing a
memcached
Application
1373
Configuration option
Default
Description
memcache.allow_failover
1
Specifies whether another server in the list
should be queried if the first server selected
fails.
memcache.max_failover_attempts
20
Specifies the number of servers to try before
returning a failure.
memcache.chunk_size
8192
Defines the size of network chunks used to
exchange data with the
memcached
server.
memcache.default_port
11211
Defines the default port to use when
communicating with the
memcached
servers.
memcache.hash_strategy
standard
Specifies which hash strategy to use. Set to
consistent
to enable servers to be added
or removed from the pool without causing the
keys to be remapped to other servers. When
set to
standard
, an older (modula) strategy
is used that potentially uses different servers
for storage.
memcache.hash_function
crc32
Specifies which function to use when
mapping keys to servers.
crc32
uses the
standard CRC32 hash.
fnv
uses the FNV-1a
hashing algorithm.
To create a connection to a
memcached
server, create a new
Memcache
object and then specify the
connection options. For example:
<?php
$cache = new Memcache;
$cache->connect('localhost',11211);
?>
This opens an immediate connection to the specified server.
To use multiple
memcached
servers, you need to add servers to the memcache object using
addServer()
:
bool Memcache::addServer ( string $host [, int $port [, bool $persistent
[, int $weight [, int $timeout [, int $retry_interval
[, bool $status [, callback $failure_callback
]]]]]]] )
The server management mechanism within the
php-memcache
module is a critical part of the interface
as it controls the main interface to the
memcached
instances and how the different instances are
selected through the hashing mechanism.
To create a simple connection to two
memcached
instances:
<?php
$cache = new Memcache;
$cache->addServer('192.168.0.100',11211);
$cache->addServer('192.168.0.101',11211);
?>
In this scenario, the instance connection is not explicitly opened, but only opened when you try to store
or retrieve a value. To enable persistent connections to
memcached
instances, set the
$persistent
argument to true. This is the default setting, and causes the connections to remain open.
To help control the distribution of keys to different instances, use the global
memcache.hash_strategy
setting. This sets the hashing mechanism used to select. You can also
add another weight to each server, which effectively increases the number of times the instance entry
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...