class Memcached (View source)

Represents a connection to a set of memcached servers.

Constants

OPT_COMPRESSION

Enables or disables payload compression. When enabled, item values longer than a certain threshold (currently 100 bytes) will be compressed during storage and decompressed during retrieval transparently.

Type: boolean, default: TRUE.

OPT_COMPRESSION_TYPE

OPT_PREFIX_KEY

This can be used to create a "domain" for your item keys. The value specified here will be prefixed to each of the keys. It cannot be longer than 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: "".

OPT_SERIALIZER

Specifies the serializer to use for serializing non-scalar values.

The valid serializers are Memcached::SERIALIZER_PHP or Memcached::SERIALIZER_IGBINARY. The latter is supported only when memcached is configured with --enable-memcached-igbinary option and the igbinary extension is loaded.

Type: integer, default: Memcached::SERIALIZER_PHP.

HAVE_IGBINARY

Indicates whether igbinary serializer support is available.

Type: boolean.

HAVE_JSON

Indicates whether JSON serializer support is available.

Type: boolean.

HAVE_MSGPACK Since: 3.0.0

Indicates whether msgpack serializer support is available.

Type: boolean.

Available as of Memcached 3.0.0.

HAVE_ENCODING

Indicate whether set_encoding_key is available

Type: boolean.

HAVE_SESSION

Feature support

HAVE_SASL

OPT_HASH

Specifies the hashing algorithm used for the item keys. The valid values are supplied via 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: integer, default: Memcached::HASH_DEFAULT

HASH_DEFAULT

The default (Jenkins one-at-a-time) item key hashing algorithm.

HASH_MD5

MD5 item key hashing algorithm.

HASH_CRC

CRC item key hashing algorithm.

HASH_FNV1_64

FNV1_64 item key hashing algorithm.

HASH_FNV1A_64

FNV1_64A item key hashing algorithm.

HASH_FNV1_32

FNV1_32 item key hashing algorithm.

HASH_FNV1A_32

FNV1_32A item key hashing algorithm.

HASH_HSIEH

Hsieh item key hashing algorithm.

HASH_MURMUR

Murmur item key hashing algorithm.

OPT_DISTRIBUTION

Specifies the method of distributing item keys to the servers.

Currently supported methods are modulo and consistent hashing. Consistent hashing delivers better distribution and allows servers to be added to the cluster with minimal cache losses.

Type: integer, default: Memcached::DISTRIBUTION_MODULA.

DISTRIBUTION_MODULA

Modulo-based key distribution algorithm.

DISTRIBUTION_CONSISTENT

Consistent hashing key distribution algorithm (based on libketama).

DISTRIBUTION_VIRTUAL_BUCKET

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.

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.

Type: boolean, default: FALSE.

OPT_LIBKETAMA_HASH

OPT_TCP_KEEPALIVE

OPT_BUFFER_WRITES

Enables or disables buffered I/O. Enabling buffered I/O causes storage commands to "buffer" instead of being sent. Any action that retrieves data causes this buffer to be sent to the remote connection.

Quitting the connection or closing down the connection will also cause the buffered data to be pushed to the remote connection.

Type: boolean, default: FALSE.

OPT_BINARY_PROTOCOL

Enable the use of the binary protocol. Please note that you cannot toggle this option on an open connection.

Type: boolean, default: FALSE.

OPT_NO_BLOCK

Enables or disables asynchronous I/O. This is the fastest transport available for storage functions.

Type: boolean, default: FALSE.

OPT_TCP_NODELAY

Enables or disables the no-delay feature for connecting sockets (may be faster in some environments).

Type: boolean, default: FALSE.

OPT_SOCKET_SEND_SIZE

The maximum socket send buffer in bytes.

Type: integer, default: varies by platform/kernel configuration.

OPT_SOCKET_RECV_SIZE

The maximum socket receive buffer in bytes.

Type: integer, default: varies by platform/kernel configuration.

OPT_CONNECT_TIMEOUT

In non-blocking mode this set the value of the timeout during socket connection, in milliseconds.

Type: integer, default: 1000.

OPT_RETRY_TIMEOUT

The amount of time, in seconds, to wait until retrying a failed connection attempt.

Type: integer, default: 0.

OPT_SEND_TIMEOUT

Socket sending timeout, in microseconds. In cases where you cannot use non-blocking I/O this will allow you to still have timeouts on the sending of data.

Type: integer, default: 0.

OPT_RECV_TIMEOUT

Socket reading timeout, in microseconds. In cases where you cannot use non-blocking I/O this will allow you to still have timeouts on the reading of data.

Type: integer, default: 0.

OPT_POLL_TIMEOUT

Timeout for connection polling, in milliseconds.

Type: integer, default: 1000.

OPT_CACHE_LOOKUPS

Enables or disables caching of DNS lookups.

Type: boolean, default: FALSE.

OPT_SERVER_FAILURE_LIMIT

Specifies the failure limit for server connection attempts. The server will be removed after this many continuous connection failures.

Type: integer, default: 0.

OPT_AUTO_EJECT_HOSTS

OPT_HASH_WITH_PREFIX_KEY

OPT_NOREPLY

OPT_SORT_HOSTS

OPT_VERIFY_KEY

OPT_USE_UDP

OPT_NUMBER_OF_REPLICAS

OPT_RANDOMIZE_REPLICA_READ

OPT_CORK

OPT_REMOVE_FAILED_SERVERS

OPT_DEAD_TIMEOUT

OPT_SERVER_TIMEOUT_LIMIT

OPT_MAX

OPT_IO_BYTES_WATERMARK

OPT_IO_KEY_PREFETCH

OPT_IO_MSG_WATERMARK

OPT_LOAD_FROM_FILE

OPT_SUPPORT_CAS

OPT_TCP_KEEPIDLE

OPT_USER_DATA

RES_SUCCESS

The operation was successful.

RES_FAILURE

The operation failed in some fashion.

RES_HOST_LOOKUP_FAILURE

DNS lookup failed.

RES_UNKNOWN_READ_FAILURE

Failed to read network data.

RES_PROTOCOL_ERROR

Bad command in memcached protocol.

RES_CLIENT_ERROR

Error on the client side.

RES_SERVER_ERROR

Error on the server side.

RES_WRITE_FAILURE

Failed to write network data.

RES_DATA_EXISTS

Failed to do compare-and-swap: item you are trying to store has been modified since you last fetched it.

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.

RES_NOTFOUND

Item with this key was not found (with "get" operation or "cas" operations).

RES_PARTIAL_READ

Partial network data read error.

RES_SOME_ERRORS

Some errors occurred during multi-get.

RES_NO_SERVERS

Server list is empty.

RES_END

End of result set.

RES_ERRNO

System error.

RES_BUFFERED

The operation was buffered.

RES_TIMEOUT

The operation timed out.

RES_BAD_KEY_PROVIDED

MEMCACHED_BAD_KEY_PROVIDED: The key provided is not a valid key.

RES_STORED

MEMCACHED_STORED: The requested object has been successfully stored on the server.

RES_DELETED

MEMCACHED_DELETED: The object requested by the key has been deleted.

RES_STAT

MEMCACHED_STAT: A “stat” command has been returned in the protocol.

RES_ITEM

MEMCACHED_ITEM: An item has been fetched (this is an internal error only).

RES_NOT_SUPPORTED

MEMCACHED_NOT_SUPPORTED: The given method is not supported in the server.

RES_FETCH_NOTFINISHED

MEMCACHED_FETCH_NOTFINISHED: A request has been made, but the server has not finished the fetch of the last request.

RES_SERVER_MARKED_DEAD

MEMCACHED_SERVER_MARKED_DEAD: The requested server has been marked dead.

RES_UNKNOWN_STAT_KEY

MEMCACHED_UNKNOWN_STAT_KEY: The server you are communicating with has a stat key which has not be defined in the protocol.

RES_INVALID_HOST_PROTOCOL

MEMCACHED_INVALID_HOST_PROTOCOL: The server you are connecting too has an invalid protocol. Most likely you are connecting to an older server that does not speak the binary protocol.

RES_MEMORY_ALLOCATION_FAILURE

MEMCACHED_MEMORY_ALLOCATION_FAILURE: An error has occurred while trying to allocate memory.

RES_E2BIG

MEMCACHED_E2BIG: Item is too large for the server to store.

RES_KEY_TOO_BIG

MEMCACHED_KEY_TOO_BIG: The key that has been provided is too large for the given server.

RES_SERVER_TEMPORARILY_DISABLED

MEMCACHED_SERVER_TEMPORARILY_DISABLED

RES_SERVER_MEMORY_ALLOCATION_FAILURE

MEMORY_ALLOCATION_FAILURE: An error has occurred while trying to allocate memory.

if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000008

RES_AUTH_PROBLEM

MEMCACHED_AUTH_PROBLEM: An unknown issue has occured during authentication.

RES_AUTH_FAILURE

MEMCACHED_AUTH_FAILURE: The credentials provided are not valid for this server.

RES_AUTH_CONTINUE

MEMCACHED_AUTH_CONTINUE: Authentication has been paused.

RES_CONNECTION_FAILURE

MEMCACHED_CONNECTION_FAILURE: A unknown error has occured while trying to connect to a server.

RES_CONNECTION_BIND_FAILURE

MEMCACHED_CONNECTION_BIND_FAILURE: We were not able to bind() to the socket.

RES_READ_FAILURE

MEMCACHED_READ_FAILURE: A read failure has occurred.

RES_DATA_DOES_NOT_EXIST

MEMCACHED_DATA_DOES_NOT_EXIST: The data requested with the key given was not found.

RES_VALUE

MEMCACHED_VALUE: A value has been returned from the server (this is an internal condition only).

RES_FAIL_UNIX_SOCKET

MEMCACHED_FAIL_UNIX_SOCKET: A connection was not established with the server via a unix domain socket.

RES_NO_KEY_PROVIDED

No key was provided.

RES_INVALID_ARGUMENTS

MEMCACHED_INVALID_ARGUMENTS: The arguments supplied to the given function were not valid.

RES_PARSE_ERROR

MEMCACHED_PARSE_ERROR: An error has occurred while trying to parse the configuration string. You should use memparse to determine what the error was.

RES_PARSE_USER_ERROR

MEMCACHED_PARSE_USER_ERROR: An error has occurred in parsing the configuration string.

RES_DEPRECATED

MEMCACHED_DEPRECATED: The method that was requested has been deprecated.

RES_IN_PROGRESS

RES_MAXIMUM_RETURN

MEMCACHED_MAXIMUM_RETURN: This in an internal only state.

ON_CONNECT

Server callbacks, if compiled with --memcached-protocol

ON_ADD

ON_APPEND

ON_DECREMENT

ON_DELETE

ON_FLUSH

ON_GET

ON_INCREMENT

ON_NOOP

ON_PREPEND

ON_QUIT

ON_REPLACE

ON_SET

ON_STAT

ON_VERSION

RESPONSE_SUCCESS

Constants used when compiled with --memcached-protocol

RESPONSE_KEY_ENOENT

RESPONSE_KEY_EEXISTS

RESPONSE_E2BIG

RESPONSE_EINVAL

RESPONSE_NOT_STORED

RESPONSE_DELTA_BADVAL

RESPONSE_NOT_MY_VBUCKET

RESPONSE_AUTH_ERROR

RESPONSE_AUTH_CONTINUE

RESPONSE_UNKNOWN_COMMAND

RESPONSE_ENOMEM

RESPONSE_NOT_SUPPORTED

RESPONSE_EINTERNAL

RESPONSE_EBUSY

RESPONSE_ETMPFAIL

RES_CONNECTION_SOCKET_CREATE_FAILURE

Failed to create network socket.

RES_PAYLOAD_FAILURE

Payload failure: could not compress/decompress or serialize/unserialize the value.

SERIALIZER_PHP

The default PHP serializer.

SERIALIZER_IGBINARY

The igbinary serializer.

Instead of textual representation it stores PHP data structures in a compact binary form, resulting in space and time gains.

SERIALIZER_JSON

The JSON serializer. Requires PHP 5.2.10+.

SERIALIZER_JSON_ARRAY

SERIALIZER_MSGPACK

The msgpack serializer.

COMPRESSION_FASTLZ

COMPRESSION_ZLIB

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.

GET_EXTENDED Since: 3.0.0

A flag for Memcached::get(), Memcached::getMulti() and Memcached::getMultiByKey() to ensure that the CAS token values are returned as well.

GET_ERROR_RETURN_VALUE

Methods

__construct(string $persistent_id = '', callable $on_new_object_cb = null, string $connection_str = '')

(PECL memcached >= 0.1.0)
Create a Memcached instance

int
getResultCode()

(PECL memcached >= 0.1.0)
Return the result code of the last operation

string
getResultMessage()

(PECL memcached >= 1.0.0)
Return the message describing the result of the last operation

mixed
get(string $key, callable $cache_cb = null, int $flags = 0)

(PECL memcached >= 0.1.0)
Retrieve an item

mixed
getByKey(string $server_key, string $key, callable $cache_cb = null, int $flags = 0)

(PECL memcached >= 0.1.0)
Retrieve an item from a specific server

mixed
getMulti(array $keys, int $flags = 0)

(PECL memcached >= 0.1.0)
Retrieve multiple items

array|false
getMultiByKey(string $server_key, array $keys, int $flags = 0)

(PECL memcached >= 0.1.0)
Retrieve multiple items from a specific server

bool
getDelayed(array $keys, bool $with_cas = null, callable $value_cb = null)

(PECL memcached >= 0.1.0)
Request multiple items

bool
getDelayedByKey(string $server_key, array $keys, bool $with_cas = null, callable $value_cb = null)

(PECL memcached >= 0.1.0)
Request multiple items from a specific server

array|false
fetch()

(PECL memcached >= 0.1.0)
Fetch the next result

array|false
fetchAll()

(PECL memcached >= 0.1.0)
Fetch all the remaining results

bool
set(string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Store an item

bool
setByKey(string $server_key, string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Store an item on a specific server

bool
touch(string $key, int $expiration = 0)

(PECL memcached >= 2.0.0)
Set a new expiration on an item

bool
touchByKey(string $server_key, string $key, int $expiration)

(PECL memcached >= 2.0.0)
Set a new expiration on an item on a specific server

bool
setMulti(array $items, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Store multiple items

bool
setMultiByKey(string $server_key, array $items, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Store multiple items on a specific server

bool
cas(float $cas_token, string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Compare and swap an item

bool
casByKey(float $cas_token, string $server_key, string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Compare and swap an item on a specific server

bool
add(string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Add an item under a new key

bool
addByKey(string $server_key, string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Add an item under a new key on a specific server

bool
append(string $key, string $value)

(PECL memcached >= 0.1.0)
Append data to an existing item

bool
appendByKey(string $server_key, string $key, string $value)

(PECL memcached >= 0.1.0)
Append data to an existing item on a specific server

bool
prepend(string $key, string $value)

(PECL memcached >= 0.1.0)
Prepend data to an existing item

bool
prependByKey(string $server_key, string $key, string $value)

(PECL memcached >= 0.1.0)
Prepend data to an existing item on a specific server

bool
replace(string $key, mixed $value, int $expiration = null, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Replace the item under an existing key

bool
replaceByKey(string $server_key, string $key, mixed $value, int $expiration = null, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Replace the item under an existing key on a specific server

bool
delete(string $key, int $time = 0)

(PECL memcached >= 0.1.0)
Delete an item

array
deleteMulti(array $keys, int $time = 0)

(PECL memcached >= 2.0.0)
Delete multiple items

bool
deleteByKey(string $server_key, string $key, int $time = 0)

(PECL memcached >= 0.1.0)
Delete an item from a specific server

bool
deleteMultiByKey(string $server_key, array $keys, int $time = 0)

(PECL memcached >= 2.0.0)
Delete multiple items from a specific server

int|false
increment(string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

(PECL memcached >= 0.1.0)
Increment numeric item's value

int|false
decrement(string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

(PECL memcached >= 0.1.0)
Decrement numeric item's value

int|false
incrementByKey(string $server_key, string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

(PECL memcached >= 2.0.0)
Increment numeric item's value, stored on a specific server

int|false
decrementByKey(string $server_key, string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

(PECL memcached >= 2.0.0)
Decrement numeric item's value, stored on a specific server

bool
addServer(string $host, int $port, int $weight = 0)

(PECL memcached >= 0.1.0)
Add a server to the server pool

bool
addServers(array $servers)

(PECL memcached >= 0.1.1)
Add multiple servers to the server pool

array
getServerList()

(PECL memcached >= 0.1.0)
Get the list of the servers in the pool

array
getServerByKey(string $server_key)

(PECL memcached >= 0.1.0)
Map a key to a server

bool
resetServerList()

(PECL memcached >= 2.0.0)
Clears all servers from the server list

bool
quit()

(PECL memcached >= 2.0.0)
Close any open connections

array|false
getStats(string $type = null)

(PECL memcached >= 0.1.0)
Get server pool statistics

array
getVersion()

(PECL memcached >= 0.1.5)
Get server pool version info

array|false
getAllKeys()

(PECL memcached >= 2.0.0)
Gets the keys stored on all the servers

bool
flush(int $delay = 0)

(PECL memcached >= 0.1.0)
Invalidate all items in the cache

mixed
getOption(int $option)

(PECL memcached >= 0.1.0)
Retrieve a Memcached option value

bool
setOption(int $option, mixed $value)

(PECL memcached >= 0.1.0)
Set a Memcached option

bool
setOptions(array $options)

(PECL memcached >= 2.0.0)
Set Memcached options

void
setSaslAuthData(string $username, string $password)

(PECL memcached >= 2.0.0)
Set the credentials to use for authentication

bool
isPersistent()

(PECL memcached >= 2.0.0)
Check if a persitent connection to memcache is being used

bool
isPristine()

(PECL memcached >= 2.0.0)
Check if the instance was recently created

bool
checkKey(string $key)

(PECL memcached >= 3.2.0)
Check if the given key is valid.

bool
flushBuffers()

Flush and send buffered commands

bool
setEncodingKey(string $key)

Sets AES encryption key (libmemcached 1.0.6 and higher)

array|false
getLastDisconnectedServer()

Returns the last disconnected server. Was added in 0.34 according to libmemcached's Changelog

int
getLastErrorErrno()

Returns the last error errno that occurred

int
getLastErrorCode()

Returns the last error code that occurred

string
getLastErrorMessage()

Returns the last error message that occurred

bool
setBucket(array $host_map, array $forward_map, int $replicas)

Sets the memcached virtual buckets

Details

__construct(string $persistent_id = '', callable $on_new_object_cb = null, string $connection_str = '')

(PECL memcached >= 0.1.0)
Create a Memcached instance

Parameters

string $persistent_id [optional]
callable $on_new_object_cb [optional]
string $connection_str [optional]

int getResultCode()

(PECL memcached >= 0.1.0)
Return the result code of the last operation

Return Value

int

Result code of the last Memcached operation.

string getResultMessage()

(PECL memcached >= 1.0.0)
Return the message describing the result of the last operation

Return Value

string

Message describing the result of the last Memcached operation.

mixed get(string $key, callable $cache_cb = null, int $flags = 0)

(PECL memcached >= 0.1.0)
Retrieve an item

Parameters

string $key

The key of the item to retrieve.

callable $cache_cb

[optional]

Read-through caching callback or NULL.

int $flags

[optional]

The flags for the get operation.

Return Value

mixed

the value stored in the cache or FALSE otherwise. The Memcached::getResultCode will return Memcached::RES_NOTFOUND if the key does not exist.

mixed getByKey(string $server_key, string $key, callable $cache_cb = null, int $flags = 0)

(PECL memcached >= 0.1.0)
Retrieve an item from a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key of the item to fetch.

callable $cache_cb

[optional]

Read-through caching callback or NULL

int $flags

[optional]

The flags for the get operation.

Return Value

mixed

the value stored in the cache or FALSE otherwise. The Memcached::getResultCode will return Memcached::RES_NOTFOUND if the key does not exist.

mixed getMulti(array $keys, int $flags = 0)

(PECL memcached >= 0.1.0)
Retrieve multiple items

Parameters

array $keys

Array of keys to retrieve.

int $flags

[optional]

The flags for the get operation.

Return Value

mixed

the array of found items or FALSE on failure. Use Memcached::getResultCode if necessary.

array|false getMultiByKey(string $server_key, array $keys, int $flags = 0)

(PECL memcached >= 0.1.0)
Retrieve multiple items from a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

array $keys

Array of keys to retrieve.

int $flags

[optional]

The flags for the get operation.

Return Value

array|false

the array of found items or FALSE on failure. Use Memcached::getResultCode if necessary.

bool getDelayed(array $keys, bool $with_cas = null, callable $value_cb = null)

(PECL memcached >= 0.1.0)
Request multiple items

Parameters

array $keys

Array of keys to request.

bool $with_cas

[optional]

Whether to request CAS token values also.

callable $value_cb

[optional]

The result callback or NULL.

Return Value

bool

TRUE on success or FALSE on failure. Use Memcached::getResultCode if necessary.

bool getDelayedByKey(string $server_key, array $keys, bool $with_cas = null, callable $value_cb = null)

(PECL memcached >= 0.1.0)
Request multiple items from a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

array $keys

Array of keys to request.

bool $with_cas

[optional]

Whether to request CAS token values also.

callable $value_cb

[optional]

The result callback or NULL.

Return Value

bool

TRUE on success or FALSE on failure. Use Memcached::getResultCode if necessary.

array|false fetch()

(PECL memcached >= 0.1.0)
Fetch the next result

Return Value

array|false

the next result or FALSE otherwise. The Memcached::getResultCode will return Memcached::RES_END if result set is exhausted.

array|false fetchAll()

(PECL memcached >= 0.1.0)
Fetch all the remaining results

Return Value

array|false

the results or FALSE on failure. Use Memcached::getResultCode if necessary.

bool set(string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Store an item

Parameters

string $key

The key under which to store the value.

mixed $value

The value to store.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. Use Memcached::getResultCode if necessary.

bool setByKey(string $server_key, string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Store an item on a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key under which to store the value.

mixed $value

The value to store.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. Use Memcached::getResultCode if necessary.

bool touch(string $key, int $expiration = 0)

(PECL memcached >= 2.0.0)
Set a new expiration on an item

Parameters

string $key

The key under which to store the value.

int $expiration

The expiration time, defaults to 0. See Expiration Times for more info.

Return Value

bool

TRUE on success or FALSE on failure. Use Memcached::getResultCode if necessary.

bool touchByKey(string $server_key, string $key, int $expiration)

(PECL memcached >= 2.0.0)
Set a new expiration on an item on a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key under which to store the value.

int $expiration

The expiration time, defaults to 0. See Expiration Times for more info.

Return Value

bool

TRUE on success or FALSE on failure. Use Memcached::getResultCode if necessary.

bool setMulti(array $items, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Store multiple items

Parameters

array $items

An array of key/value pairs to store on the server.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. Use Memcached::getResultCode if necessary.

bool setMultiByKey(string $server_key, array $items, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Store multiple items on a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

array $items

An array of key/value pairs to store on the server.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. Use Memcached::getResultCode if necessary.

bool cas(float $cas_token, string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Compare and swap an item

Parameters

float $cas_token

Unique value associated with the existing item. Generated by memcache.

string $key

The key under which to store the value.

mixed $value

The value to store.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_DATA_EXISTS if the item you are trying to store has been modified since you last fetched it.

bool casByKey(float $cas_token, string $server_key, string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Compare and swap an item on a specific server

Parameters

float $cas_token

Unique value associated with the existing item. Generated by memcache.

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key under which to store the value.

mixed $value

The value to store.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_DATA_EXISTS if the item you are trying to store has been modified since you last fetched it.

bool add(string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Add an item under a new key

Parameters

string $key

The key under which to store the value.

mixed $value

The value to store.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTSTORED if the key already exists.

bool addByKey(string $server_key, string $key, mixed $value, int $expiration = 0, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Add an item under a new key on a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key under which to store the value.

mixed $value

The value to store.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTSTORED if the key already exists.

bool append(string $key, string $value)

(PECL memcached >= 0.1.0)
Append data to an existing item

Parameters

string $key

The key under which to store the value.

string $value

The string to append.

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTSTORED if the key does not exist.

bool appendByKey(string $server_key, string $key, string $value)

(PECL memcached >= 0.1.0)
Append data to an existing item on a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key under which to store the value.

string $value

The string to append.

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTSTORED if the key does not exist.

bool prepend(string $key, string $value)

(PECL memcached >= 0.1.0)
Prepend data to an existing item

Parameters

string $key

The key of the item to prepend the data to.

string $value

The string to prepend.

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTSTORED if the key does not exist.

bool prependByKey(string $server_key, string $key, string $value)

(PECL memcached >= 0.1.0)
Prepend data to an existing item on a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key of the item to prepend the data to.

string $value

The string to prepend.

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTSTORED if the key does not exist.

bool replace(string $key, mixed $value, int $expiration = null, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Replace the item under an existing key

Parameters

string $key

The key under which to store the value.

mixed $value

The value to store.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTSTORED if the key does not exist.

bool replaceByKey(string $server_key, string $key, mixed $value, int $expiration = null, int $udf_flags = 0)

(PECL memcached >= 0.1.0)
Replace the item under an existing key on a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key under which to store the value.

mixed $value

The value to store.

int $expiration

[optional]

The expiration time, defaults to 0. See Expiration Times for more info.

int $udf_flags [optional]

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTSTORED if the key does not exist.

bool delete(string $key, int $time = 0)

(PECL memcached >= 0.1.0)
Delete an item

Parameters

string $key

The key to be deleted.

int $time

[optional]

The amount of time the server will wait to delete the item.

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTFOUND if the key does not exist.

array deleteMulti(array $keys, int $time = 0)

(PECL memcached >= 2.0.0)
Delete multiple items

Parameters

array $keys

The keys to be deleted.

int $time

[optional]

The amount of time the server will wait to delete the items.

Return Value

array

Returns array indexed by keys and where values are indicating whether operation succeeded or not. The Memcached::getResultCode will return Memcached::RES_NOTFOUND if the key does not exist.

bool deleteByKey(string $server_key, string $key, int $time = 0)

(PECL memcached >= 0.1.0)
Delete an item from a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key to be deleted.

int $time

[optional]

The amount of time the server will wait to delete the item.

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTFOUND if the key does not exist.

bool deleteMultiByKey(string $server_key, array $keys, int $time = 0)

(PECL memcached >= 2.0.0)
Delete multiple items from a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

array $keys

The keys to be deleted.

int $time

[optional]

The amount of time the server will wait to delete the items.

Return Value

bool

TRUE on success or FALSE on failure. The Memcached::getResultCode will return Memcached::RES_NOTFOUND if the key does not exist.

int|false increment(string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

(PECL memcached >= 0.1.0)
Increment numeric item's value

Parameters

string $key

The key of the item to increment.

int $offset

[optional]

The amount by which to increment the item's value.

int $initial_value

[optional]

The value to set the item to if it doesn't currently exist.

int $expiry

[optional]

The expiry time to set on the item.

Return Value

int|false

new item's value on success or FALSE on failure.

int|false decrement(string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

(PECL memcached >= 0.1.0)
Decrement numeric item's value

Parameters

string $key

The key of the item to decrement.

int $offset

[optional]

The amount by which to decrement the item's value.

int $initial_value

[optional]

The value to set the item to if it doesn't currently exist.

int $expiry

[optional]

The expiry time to set on the item.

Return Value

int|false

item's new value on success or FALSE on failure.

int|false incrementByKey(string $server_key, string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

(PECL memcached >= 2.0.0)
Increment numeric item's value, stored on a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key of the item to increment.

int $offset

[optional]

The amount by which to increment the item's value.

int $initial_value

[optional]

The value to set the item to if it doesn't currently exist.

int $expiry

[optional]

The expiry time to set on the item.

Return Value

int|false

new item's value on success or FALSE on failure.

int|false decrementByKey(string $server_key, string $key, int $offset = 1, int $initial_value = 0, int $expiry = 0)

(PECL memcached >= 2.0.0)
Decrement numeric item's value, stored on a specific server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

string $key

The key of the item to decrement.

int $offset

[optional]

The amount by which to decrement the item's value.

int $initial_value

[optional]

The value to set the item to if it doesn't currently exist.

int $expiry

[optional]

The expiry time to set on the item.

Return Value

int|false

item's new value on success or FALSE on failure.

bool addServer(string $host, int $port, int $weight = 0)

(PECL memcached >= 0.1.0)
Add a server to the server pool

Parameters

string $host

The hostname of the memcache server. If the hostname is invalid, data-related operations will set Memcached::RES_HOST_LOOKUP_FAILURE result code.

int $port

The port on which memcache is running. Usually, this is 11211.

int $weight

[optional]

The weight of the server relative to the total weight of all the servers in the pool. This controls the probability of the server being selected for operations. This is used only with consistent distribution option and usually corresponds to the amount of memory available to memcache on that server.

Return Value

bool

TRUE on success or FALSE on failure.

bool addServers(array $servers)

(PECL memcached >= 0.1.1)
Add multiple servers to the server pool

Parameters

array $servers

Return Value

bool

TRUE on success or FALSE on failure.

array getServerList()

(PECL memcached >= 0.1.0)
Get the list of the servers in the pool

Return Value

array

The list of all servers in the server pool.

array getServerByKey(string $server_key)

(PECL memcached >= 0.1.0)
Map a key to a server

Parameters

string $server_key

The key identifying the server to store the value on or retrieve it from. Instead of hashing on the actual key for the item, we hash on the server key when deciding which memcached server to talk to. This allows related items to be grouped together on a single server for efficiency with multi operations.

Return Value

array

an array containing three keys of host, port, and weight on success or FALSE on failure. Use Memcached::getResultCode if necessary.

bool resetServerList()

(PECL memcached >= 2.0.0)
Clears all servers from the server list

Return Value

bool

TRUE on success or FALSE on failure.

bool quit()

(PECL memcached >= 2.0.0)
Close any open connections

Return Value

bool

TRUE on success or FALSE on failure.

array|false getStats(string $type = null)

(PECL memcached >= 0.1.0)
Get server pool statistics

Parameters

string $type

items, slabs, sizes ...

Return Value

array|false

Array of server statistics, one entry per server.

array getVersion()

(PECL memcached >= 0.1.5)
Get server pool version info

Return Value

array

Array of server versions, one entry per server.

array|false getAllKeys()

(PECL memcached >= 2.0.0)
Gets the keys stored on all the servers

Return Value

array|false

the keys stored on all the servers on success or FALSE on failure.

bool flush(int $delay = 0)

(PECL memcached >= 0.1.0)
Invalidate all items in the cache

Parameters

int $delay

[optional]

Numer of seconds to wait before invalidating the items.

Return Value

bool

TRUE on success or FALSE on failure. Use Memcached::getResultCode if necessary.

mixed getOption(int $option)

(PECL memcached >= 0.1.0)
Retrieve a Memcached option value

Parameters

int $option

One of the Memcached::OPT_* constants.

Return Value

mixed

the value of the requested option, or FALSE on error.

bool setOption(int $option, mixed $value)

(PECL memcached >= 0.1.0)
Set a Memcached option

Parameters

int $option
mixed $value

Return Value

bool

TRUE on success or FALSE on failure.

bool setOptions(array $options)

(PECL memcached >= 2.0.0)
Set Memcached options

Parameters

array $options

An associative array of options where the key is the option to set and the value is the new value for the option.

Return Value

bool

TRUE on success or FALSE on failure.

void setSaslAuthData(string $username, string $password)

(PECL memcached >= 2.0.0)
Set the credentials to use for authentication

Parameters

string $username

The username to use for authentication.

string $password

The password to use for authentication.

Return Value

void

bool isPersistent()

(PECL memcached >= 2.0.0)
Check if a persitent connection to memcache is being used

Return Value

bool

true if Memcache instance uses a persistent connection, false otherwise.

bool isPristine()

(PECL memcached >= 2.0.0)
Check if the instance was recently created

Return Value

bool

the true if instance is recently created, false otherwise.

bool checkKey(string $key)

(PECL memcached >= 3.2.0)
Check if the given key is valid.

Parameters

string $key

Return Value

bool

bool flushBuffers()

Flush and send buffered commands

Return Value

bool

bool setEncodingKey(string $key)

Sets AES encryption key (libmemcached 1.0.6 and higher)

Parameters

string $key

Return Value

bool

array|false getLastDisconnectedServer()

Returns the last disconnected server. Was added in 0.34 according to libmemcached's Changelog

Return Value

array|false

int getLastErrorErrno()

Returns the last error errno that occurred

Return Value

int

int getLastErrorCode()

Returns the last error code that occurred

Return Value

int

string getLastErrorMessage()

Returns the last error message that occurred

Return Value

string

bool setBucket(array $host_map, array $forward_map, int $replicas)

Sets the memcached virtual buckets

Parameters

array $host_map
array $forward_map
int $replicas

Return Value

bool