The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
Memcached::OPT_COMPRESSION
Memcached::OPT_COMPRESSION_TYPE
Memcached::COMPRESSION_FASTLZ
,
Memcached::COMPRESSION_ZLIB
and
Memcached::COMPRESSION_ZSTD
.
Type: int , default: Memcached::COMPRESSION_FASTLZ
.
Memcached::COMPRESSION_FASTLZ
Memcached::COMPRESSION_ZLIB
Memcached::COMPRESSION_ZSTD
Memcached::OPT_COMPRESSION_LEVEL
Memcached::COMPRESSION_FASTLZ
does not support compression levels.Memcached::COMPRESSION_ZSTD
: minimum level is -22
and maximum level is 22
.Memcached::COMPRESSION_ZLIB
: minimum level is 0
and maximum level is 9
.Type: int , default: 3
.
Memcached::OPT_SERIALIZER
Memcached::SERIALIZER_PHP
,
Memcached::SERIALIZER_IGBINARY
,
Memcached::SERIALIZER_JSON
,
Memcached::SERIALIZER_JSON_ARRAY
and
Memcached::SERIALIZER_MSGPACK
.
Type: int , default: Memcached::SERIALIZER_IGBINARY
if available,
then Memcached::SERIALIZER_MSGPACK
if available,
then Memcached::SERIALIZER_PHP
.
Memcached::SERIALIZER_PHP
The default PHP serializer.
Memcached::SERIALIZER_IGBINARY
Memcached::SERIALIZER_JSON
The JSON serializer. This serializer deserializes JSON to an object.
Memcached::SERIALIZER_JSON_ARRAY
Memcached::SERIALIZER_MSGPACK
msgpack
extension is loaded.
Memcached::OPT_PREFIX_KEY
128
characters and will reduce the
maximum available key size. The prefix is applied only to the item keys,
not to the server keys.
Type: string , default: ""
.
Memcached::OPT_HASH
Memcached::HASH_*
constants.
Each hash algorithm has its advantages and its disadvantages. Go with the
default if you don't know or don't care.
Type: int , default: Memcached::HASH_DEFAULT
Memcached::HASH_DEFAULT
The default (Jenkins one-at-a-time) item key hashing algorithm.
Memcached::HASH_MD5
MD5 item key hashing algorithm.
Memcached::HASH_CRC
CRC item key hashing algorithm.
Memcached::HASH_FNV1_64
FNV1_64 item key hashing algorithm.
Memcached::HASH_FNV1A_64
FNV1_64A item key hashing algorithm.
Memcached::HASH_FNV1_32
FNV1_32 item key hashing algorithm.
Memcached::HASH_FNV1A_32
FNV1_32A item key hashing algorithm.
Memcached::HASH_HSIEH
Hsieh item key hashing algorithm.
Memcached::HASH_MURMUR
Murmur item key hashing algorithm.
Memcached::OPT_DISTRIBUTION
Type: int , default: Memcached::DISTRIBUTION_MODULA
.
Memcached::DISTRIBUTION_MODULA
Modulo-based key distribution algorithm.
Memcached::DISTRIBUTION_CONSISTENT
Consistent hashing key distribution algorithm (based on libketama).
Memcached::DISTRIBUTION_VIRTUAL_BUCKET
Memcached::OPT_LIBKETAMA_COMPATIBLE
Enables or disables compatibility with libketama-like behavior. When enabled, the item key hashing algorithm is set to MD5 and distribution is set to be weighted consistent hashing distribution. This is useful because other libketama-based clients (Python, Ruby, etc.) with the same server configuration will be able to access the keys transparently.
Note:
It is highly recommended to enable this option if you want to use consistent hashing, and it may be enabled by default in future releases.
Memcached::OPT_LIBKETAMA_HASH
Type: int .
Memcached::OPT_TCP_KEEPALIVE
Memcached::OPT_BUFFER_WRITES
Memcached::OPT_BINARY_PROTOCOL
Memcached::OPT_NO_BLOCK
Memcached::OPT_NOREPLY
Memcached::OPT_TCP_NODELAY
Memcached::OPT_SOCKET_SEND_SIZE
Type: int , default: varies by platform/kernel configuration.
Memcached::OPT_SOCKET_RECV_SIZE
Type: int , default: varies by platform/kernel configuration.
Memcached::OPT_CONNECT_TIMEOUT
Type: int , default: 1000
.
Memcached::OPT_RETRY_TIMEOUT
Type: int , default: 2
.
Memcached::OPT_DEAD_TIMEOUT
0
means no retry.
Type: int , default: 0
.
Memcached::OPT_SEND_TIMEOUT
Type: int , default: 0
.
Memcached::OPT_RECV_TIMEOUT
Type: int , default: 0
.
Memcached::OPT_POLL_TIMEOUT
Type: int , default: 1000
.
Memcached::OPT_CACHE_LOOKUPS
Memcached::OPT_SERVER_FAILURE_LIMIT
Type: int , default: 5
.
Memcached::OPT_SERVER_TIMEOUT_LIMIT
Type: int , default: 0
.
Memcached::OPT_AUTO_EJECT_HOSTS
Removes disabled servers from the list. Use together with
Memcached::OPT_SERVER_FAILURE_LIMIT
and
Memcached::OPT_SERVER_TIMEOUT_LIMIT
.
Note:
This option is replaced by
Memcached::OPT_REMOVE_FAILED_SERVERS
.
Memcached::OPT_VERIFY_KEY
Memcached::OPT_USE_UDP
Memcached::OPT_NUMBER_OF_REPLICAS
Type: int , default: 0
.
Memcached::OPT_RANDOMIZE_REPLICA_READS
Memcached::OPT_REMOVE_FAILED_SERVERS
Memcached::OPT_SERVER_FAILURE_LIMIT
and
Memcached::OPT_SERVER_TIMEOUT_LIMIT
.
Memcached::HAVE_IGBINARY
Type: bool .
Memcached::HAVE_JSON
Type: bool .
Memcached::HAVE_MSGPACK
Type: bool .
Available as of Memcached 3.0.0.
Memcached::HAVE_ZSTD
Type: bool .
Available as of Memcached 3.3.0.
Memcached::HAVE_ENCODING
Type: bool .
Available as of Memcached 3.1.0.
Memcached::HAVE_SESSION
Type: bool .
Available as of Memcached 3.0.0.
Memcached::HAVE_SASL
Type: bool .
Available as of Memcached 3.0.0.
Memcached::GET_EXTENDED
A flag for Memcached::get() , Memcached::getMulti() and Memcached::getMultiByKey() to ensure that the CAS token values are returned as well.
Available as of Memcached 3.0.0.
Memcached::GET_PRESERVE_ORDER
A flag for Memcached::getMulti() and
Memcached::getMultiByKey() to ensure that the keys are
returned in the same order as they were requested in. Non-existing keys
get a default value of null
.
Memcached::RES_SUCCESS
The operation was successful.
Memcached::RES_FAILURE
The operation failed in some fashion.
Memcached::RES_HOST_LOOKUP_FAILURE
DNS lookup failed.
Memcached::RES_UNKNOWN_READ_FAILURE
Failed to read network data.
Memcached::RES_PROTOCOL_ERROR
Bad command in memcached protocol.
Memcached::RES_CLIENT_ERROR
Error on the client side.
Memcached::RES_SERVER_ERROR
Error on the server side.
Memcached::RES_WRITE_FAILURE
Failed to write network data.
Memcached::RES_DATA_EXISTS
Failed to do compare-and-swap: item you are trying to store has been modified since you last fetched it.
Memcached::RES_NOTSTORED
Item was not stored: but not because of an error. This normally means that either the condition for an "add" or a "replace" command wasn't met, or that the item is in a delete queue.
Memcached::RES_NOTFOUND
Item with this key was not found (with "get" operation or "cas" operations).
Memcached::RES_PARTIAL_READ
Partial network data read error.
Memcached::RES_SOME_ERRORS
Some errors occurred during multi-get.
Memcached::RES_NO_SERVERS
Server list is empty.
Memcached::RES_END
End of result set.
Memcached::RES_ERRNO
System error.
Memcached::RES_BUFFERED
The operation was buffered.
Memcached::RES_TIMEOUT
The operation timed out.
Memcached::RES_BAD_KEY_PROVIDED
Bad key.
Memcached::RES_STORED
Memcached::RES_DELETED
Memcached::RES_STAT
Memcached::RES_ITEM
Memcached::RES_NOT_SUPPORTED
Memcached::RES_FETCH_NOTFINISHED
Memcached::RES_SERVER_MARKED_DEAD
Memcached::RES_UNKNOWN_STAT_KEY
Memcached::RES_INVALID_HOST_PROTOCOL
Memcached::RES_MEMORY_ALLOCATION_FAILURE
Memcached::RES_CONNECTION_SOCKET_CREATE_FAILURE
Failed to create network socket.
Memcached::RES_PAYLOAD_FAILURE
Payload failure: could not compress/decompress or serialize/unserialize the value.
Memcached::RES_AUTH_PROBLEM
Available as of Memcached 3.0.0.
Memcached::RES_AUTH_FAILURE
Available as of Memcached 3.0.0.
Memcached::RES_AUTH_CONTINUE
Available as of Memcached 3.0.0.
Memcached::RES_E2BIG
Available as of Memcached 3.0.0.
Memcached::RES_KEY_TOO_BIG
Available as of Memcached 3.0.0.
Memcached::RES_SERVER_TEMPORARILY_DISABLED
Available as of Memcached 3.0.0.
Memcached::RES_SERVER_MEMORY_ALLOCATION_FAILURE
Available as of Memcached 3.0.0.
RES_SUCCESS = 0
RES_FAILURE = 1
RES_HOST_LOOKUP_FAILURE = 2
RES_UNKNOWN_READ_FAILURE = 7
RES_PROTOCOL_ERROR = 8
RES_CLIENT_ERROR = 9
RES_SERVER_ERROR = 10
RES_WRITE_FAILURE = 5
RES_DATA_EXISTS = 12
RES_NOTSTORED = 14
RES_NOTFOUND = 16
RES_PARTIAL_READ = 18
RES_SOME_ERRORS = 19
RES_NO_SERVERS = 20
RES_END = 21
RES_ERRNO = 26
RES_BUFFERED = 32
RES_TIMEOUT = 31
RES_BAD_KEY_PROVIDED = 33
RES_CONNECTION_SOCKET_CREATE_FAILURE = 11
RES_PAYLOAD_FAILURE = -1001
As per a StackOverflow answer (http://stackoverflow.com/a/9042985/102960, by @rid), this is the current list of Memcached Response constants:
00 = MEMCACHED_SUCCESS
01 = MEMCACHED_FAILURE
02 = MEMCACHED_HOST_LOOKUP_FAILURE // getaddrinfo() and getnameinfo() only
03 = MEMCACHED_CONNECTION_FAILURE
04 = MEMCACHED_CONNECTION_BIND_FAILURE // DEPRECATED see MEMCACHED_HOST_LOOKUP_FAILURE
05 = MEMCACHED_WRITE_FAILURE
06 = MEMCACHED_READ_FAILURE
07 = MEMCACHED_UNKNOWN_READ_FAILURE
08 = MEMCACHED_PROTOCOL_ERROR
09 = MEMCACHED_CLIENT_ERROR
10 = MEMCACHED_SERVER_ERROR // Server returns "SERVER_ERROR"
11 = MEMCACHED_ERROR // Server returns "ERROR"
12 = MEMCACHED_DATA_EXISTS
13 = MEMCACHED_DATA_DOES_NOT_EXIST
14 = MEMCACHED_NOTSTORED
15 = MEMCACHED_STORED
16 = MEMCACHED_NOTFOUND
17 = MEMCACHED_MEMORY_ALLOCATION_FAILURE
18 = MEMCACHED_PARTIAL_READ
19 = MEMCACHED_SOME_ERRORS
20 = MEMCACHED_NO_SERVERS
21 = MEMCACHED_END
22 = MEMCACHED_DELETED
23 = MEMCACHED_VALUE
24 = MEMCACHED_STAT
25 = MEMCACHED_ITEM
26 = MEMCACHED_ERRNO
27 = MEMCACHED_FAIL_UNIX_SOCKET // DEPRECATED
28 = MEMCACHED_NOT_SUPPORTED
29 = MEMCACHED_NO_KEY_PROVIDED /* Deprecated. Use MEMCACHED_BAD_KEY_PROVIDED! */
30 = MEMCACHED_FETCH_NOTFINISHED
31 = MEMCACHED_TIMEOUT
32 = MEMCACHED_BUFFERED
33 = MEMCACHED_BAD_KEY_PROVIDED
34 = MEMCACHED_INVALID_HOST_PROTOCOL
35 = MEMCACHED_SERVER_MARKED_DEAD
36 = MEMCACHED_UNKNOWN_STAT_KEY
37 = MEMCACHED_E2BIG
38 = MEMCACHED_INVALID_ARGUMENTS
39 = MEMCACHED_KEY_TOO_BIG
40 = MEMCACHED_AUTH_PROBLEM
41 = MEMCACHED_AUTH_FAILURE
42 = MEMCACHED_AUTH_CONTINUE
43 = MEMCACHED_PARSE_ERROR
44 = MEMCACHED_PARSE_USER_ERROR
45 = MEMCACHED_DEPRECATED
46 = MEMCACHED_IN_PROGRESS
47 = MEMCACHED_SERVER_TEMPORARILY_DISABLED
48 = MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE
49 = MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */
11 = MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE = MEMCACHED_ERROR
Note that with Memcached::OPT_BINARY_PROTOCOL enabled there is some (possibly significant) size overhead added at the TCP level.
If you have a high volume of small values being get/set, you should analyze the effect of this option on your overall traffic size with a network tool (e.g. tcpdump) before enabling it, especially if you pay for traffic in/out of your memcache instance.
Apparently there is a bug in libmemcached where connect timeout does not work when OPT_NO_BLOCK is set as well.
The bug and related blocking bugs are discussed here:
https://bugs.launchpad.net/libmemcached/+bug/583031
We confirmed this in libmemcached version 0.43
Be sure to test some memcache servers in your pool being unavailable (no route to host and memcache service down) to ensure that timeout settings are working correctly.
Memcached::OPT_SERVER_FAILURE_LIMIT - once a server has hit this limit, the client's getResultMessage() will return "SERVER IS MARKED DEAD." Further gets() for keys hashing to this server will continue returning this message, as will sets() hashing to the dead server.
Version 2.0.01b supports a constant Memcached::OPT_AUTO_EJECT_HOSTS which allows automatic rebalancing of the cluster/automatic failover handling.