class MemcachePool (View source)

Methods

bool
connect(string $host, int $port, int $timeout = 1)

(PECL memcache >= 0.2.0)
Open memcached server connection

bool
addServer(string $host, int $port = 11211, bool $persistent = true, int $weight = null, int $timeout = 1, int $retry_interval = 15, bool $status = true, callable $failure_callback = null, int $timeoutms = null)

(PECL memcache >= 2.0.0)
Add a memcached server to connection pool

bool
setServerParams(string $host, int $port = 11211, int $timeout = 1, int $retry_interval = 15, bool $status = true, callable $failure_callback = null)

(PECL memcache >= 2.1.0)
Changes server parameters and status at runtime

setFailureCallback()

No description

int
getServerStatus(string $host, int $port = 11211)

(PECL memcache >= 2.1.0)
Returns server status

findServer()

No description

string|false
getVersion()

(PECL memcache >= 0.2.0)
Return version of the server

bool
add(string $key, mixed $var, int $flag = null, int $expire = null)

(PECL memcache >= 2.0.0)
Add an item to the server. If the key already exists, the value will not be added and FALSE will be returned.

bool
set(string $key, mixed $var, int $flag = null, int $expire = null)

(PECL memcache >= 0.2.0)
Stores an item var with key on the memcached server. Parameter expire is expiration time in seconds.

bool
replace(string $key, mixed $var, int $flag = null, int $expire = null)

(PECL memcache >= 0.2.0)
Replace value of the existing item

cas()

No description

append()

No description

string
prepend()

No description

string|array|false
get(string|array $key, int|array $flags = null)

(PECL memcache >= 0.2.0)
Retrieve item from the server

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

(PECL memcache >= 0.2.0)
Delete item from the server https://secure.php.net/manual/en/memcache.delete.php

array|false
getStats(string $type = null, int $slabid = null, int $limit = 100)

(PECL memcache >= 0.2.0)
Get statistics of the server

array|false
getExtendedStats(string $type = null, int $slabid = null, int $limit = 100)

(PECL memcache >= 2.0.0)
Get statistics from all servers in pool

bool
setCompressThreshold(int $thresold, float $min_saving = 0.2)

(PECL memcache >= 2.0.0)
Enable automatic compression of large values

int|false
increment(string $key, int $value = 1)

(PECL memcache >= 0.2.0)
Increment item's value

int|false
decrement(string $key, int $value = 1)

(PECL memcache >= 0.2.0)
Decrement item's value

bool
close()

(PECL memcache >= 0.4.0)
Close memcached server connection

bool
flush()

(PECL memcache >= 1.0.0)
Flush all existing items at the server

Details

bool connect(string $host, int $port, int $timeout = 1)

(PECL memcache >= 0.2.0)
Open memcached server connection

Parameters

string $host

Point to the host where memcached is listening for connections. This parameter may also specify other transports like unix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.

int $port

[optional]

Point to the port where memcached is listening for connections. Set this parameter to 0 when using UNIX domain sockets.

Please note: port defaults to https://php.net/manual/en/memcache.ini.php#ini.memcache.default-port memcache.default_port if not specified. For this reason it is wise to specify the port explicitly in this method call.

int $timeout

[optional]

Value in seconds which will be used for connecting to the daemon. Think twice before changing the default value of 1 second - you can lose all the advantages of caching if your connection is too slow.

Return Value

bool

Returns TRUE on success or FALSE on failure.

bool addServer(string $host, int $port = 11211, bool $persistent = true, int $weight = null, int $timeout = 1, int $retry_interval = 15, bool $status = true, callable $failure_callback = null, int $timeoutms = null)

(PECL memcache >= 2.0.0)
Add a memcached server to connection pool

Parameters

string $host

Point to the host where memcached is listening for connections. This parameter may also specify other transports like unix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.

int $port

[optional]

Point to the port where memcached is listening for connections. Set this parameter to 0 when using UNIX domain sockets.

Please note: port defaults to memcache.default_port if not specified. For this reason it is wise to specify the port explicitly in this method call.

bool $persistent

[optional]

Controls the use of a persistent connection. Default to TRUE.

int $weight

[optional]

Number of buckets to create for this server which in turn control its probability of it being selected. The probability is relative to the total weight of all servers.

int $timeout

[optional]

Value in seconds which will be used for connecting to the daemon. Think twice before changing the default value of 1 second - you can lose all the advantages of caching if your connection is too slow.

int $retry_interval

[optional]

Controls how often a failed server will be retried, the default value is 15 seconds. Setting this parameter to -1 disables automatic retry. Neither this nor the persistent parameter has any effect when the extension is loaded dynamically via dl.

Each failed connection struct has its own timeout and before it has expired the struct will be skipped when selecting backends to serve a request. Once expired the connection will be successfully reconnected or marked as failed for another retry_interval seconds. The typical effect is that each web server child will retry the connection about every retry_interval seconds when serving a page.

bool $status

[optional]

Controls if the server should be flagged as online. Setting this parameter to FALSE and retry_interval to -1 allows a failed server to be kept in the pool so as not to affect the key distribution algorithm. Requests for this server will then failover or fail immediately depending on the memcache.allow_failover setting. Default to TRUE, meaning the server should be considered online.

callable $failure_callback

[optional]

Allows the user to specify a callback function to run upon encountering an error. The callback is run before failover is attempted. The function takes two parameters, the hostname and port of the failed server.

int $timeoutms

[optional]

Return Value

bool

TRUE on success or FALSE on failure.

bool setServerParams(string $host, int $port = 11211, int $timeout = 1, int $retry_interval = 15, bool $status = true, callable $failure_callback = null)

(PECL memcache >= 2.1.0)
Changes server parameters and status at runtime

Parameters

string $host

Point to the host where memcached is listening for connections.

.
int $port

[optional]

Point to the port where memcached is listening for connections.

int $timeout

[optional]

Value in seconds which will be used for connecting to the daemon. Think twice before changing the default value of 1 second - you can lose all the advantages of caching if your connection is too slow.

int $retry_interval

[optional]

Controls how often a failed server will be retried, the default value is 15 seconds. Setting this parameter to -1 disables automatic retry. Neither this nor the persistent parameter has any effect when the extension is loaded dynamically via https://secure.php.net/manual/en/function.dl.php dl().

bool $status

[optional]

Controls if the server should be flagged as online. Setting this parameter to FALSE and retry_interval to -1 allows a failed server to be kept in the pool so as not to affect the key distribution algorithm. Requests for this server will then failover or fail immediately depending on the memcache.allow_failover setting. Default to TRUE, meaning the server should be considered online.

callable $failure_callback

[optional]

Allows the user to specify a callback function to run upon encountering an error. The callback is run before failover is attempted. The function takes two parameters, the hostname and port of the failed server.

Return Value

bool

Returns TRUE on success or FALSE on failure.

setFailureCallback()

No description

int getServerStatus(string $host, int $port = 11211)

(PECL memcache >= 2.1.0)
Returns server status

Parameters

string $host

Point to the host where memcached is listening for connections.

int $port

Point to the port where memcached is listening for connections.

Return Value

int

Returns a the servers status. 0 if server is failed, non-zero otherwise

findServer()

No description

string|false getVersion()

(PECL memcache >= 0.2.0)
Return version of the server

Return Value

string|false

Returns a string of server version number or FALSE on failure.

bool add(string $key, mixed $var, int $flag = null, int $expire = null)

(PECL memcache >= 2.0.0)
Add an item to the server. If the key already exists, the value will not be added and FALSE will be returned.

Parameters

string $key

The key that will be associated with the item.

mixed $var

The variable to store. Strings and integers are stored as is, other types are stored serialized.

int $flag

[optional]

Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).

int $expire

[optional]

Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).

Return Value

bool

Returns TRUE on success or FALSE on failure. Returns FALSE if such key already exist. For the rest Memcache::add() behaves similarly to Memcache::set().

bool set(string $key, mixed $var, int $flag = null, int $expire = null)

(PECL memcache >= 0.2.0)
Stores an item var with key on the memcached server. Parameter expire is expiration time in seconds.

If it's 0, the item never expires (but memcached server doesn't guarantee this item to be stored all the time, it could be deleted from the cache to make place for other items). You can use MEMCACHE_COMPRESSED constant as flag value if you want to use on-the-fly compression (uses zlib).

Parameters

string $key

The key that will be associated with the item.

mixed $var

The variable to store. Strings and integers are stored as is, other types are stored serialized.

int $flag

[optional] Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).

int $expire

[optional] Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).

Return Value

bool

Returns TRUE on success or FALSE on failure.

bool replace(string $key, mixed $var, int $flag = null, int $expire = null)

(PECL memcache >= 0.2.0)
Replace value of the existing item

Parameters

string $key

The key that will be associated with the item.

mixed $var

The variable to store. Strings and integers are stored as is, other types are stored serialized.

int $flag

[optional]

Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).

int $expire

[optional]

Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).

Return Value

bool

Returns TRUE on success or FALSE on failure.

cas()

No description

append()

No description

string prepend()

No description

Return Value

string

string|array|false get(string|array $key, int|array $flags = null)

(PECL memcache >= 0.2.0)
Retrieve item from the server

Parameters

string|array $key

The key or array of keys to fetch.

int|array $flags

[optional]

If present, flags fetched along with the values will be written to this parameter. These flags are the same as the ones given to for example https://php.net/manual/en/memcache.set.php Memcache::set(). The lowest byte of the int is reserved for pecl/memcache internal usage (e.g. to indicate compression and serialization status).

Return Value

string|array|false

Returns the string associated with the key or an array of found key-value pairs when key is an https://php.net/manual/en/language.types.array.php array. Returns FALSE on failure, key is not found or key is an empty https://php.net/manual/en/language.types.array.php array.

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

(PECL memcache >= 0.2.0)
Delete item from the server https://secure.php.net/manual/en/memcache.delete.php

Parameters

string $key

The key associated with the item to delete.

int $timeout

[optional] This deprecated parameter is not supported, and defaults to 0 seconds. Do not use this parameter.

Return Value

bool

Returns TRUE on success or FALSE on failure.

array|false getStats(string $type = null, int $slabid = null, int $limit = 100)

(PECL memcache >= 0.2.0)
Get statistics of the server

Parameters

string $type

[optional]

The type of statistics to fetch. Valid values are {reset, malloc, maps, cachedump, slabs, items, sizes}. According to the memcached protocol spec these additional arguments "are subject to change for the convenience of memcache developers".

int $slabid

[optional]

Used in conjunction with type set to cachedump to identify the slab to dump from. The cachedump command ties up the server and is strictly to be used for debugging purposes.

int $limit

[optional]

Used in conjunction with type set to cachedump to limit the number of entries to dump.

Return Value

array|false

Returns an associative array of server statistics or FALSE on failure.

array|false getExtendedStats(string $type = null, int $slabid = null, int $limit = 100)

(PECL memcache >= 2.0.0)
Get statistics from all servers in pool

Parameters

string $type

[optional]

The type of statistics to fetch. Valid values are {reset, malloc, maps, cachedump, slabs, items, sizes}. According to the memcached protocol spec these additional arguments "are subject to change for the convenience of memcache developers".

int $slabid

[optional]

Used in conjunction with type set to cachedump to identify the slab to dump from. The cachedump command ties up the server and is strictly to be used for debugging purposes.

int $limit

Used in conjunction with type set to cachedump to limit the number of entries to dump.

Return Value

array|false

Returns a two-dimensional associative array of server statistics or FALSE Returns a two-dimensional associative array of server statistics or FALSE on failure.

bool setCompressThreshold(int $thresold, float $min_saving = 0.2)

(PECL memcache >= 2.0.0)
Enable automatic compression of large values

Parameters

int $thresold

Controls the minimum value length before attempting to compress automatically.

float $min_saving

[optional]

Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1. Default value is 0.2 giving a minimum 20% compression savings.

Return Value

bool

Returns TRUE on success or FALSE on failure.

int|false increment(string $key, int $value = 1)

(PECL memcache >= 0.2.0)
Increment item's value

Parameters

string $key

Key of the item to increment.

int $value

[optional] increment the item by value

Return Value

int|false

Returns new items value on success or FALSE on failure.

int|false decrement(string $key, int $value = 1)

(PECL memcache >= 0.2.0)
Decrement item's value

Parameters

string $key

Key of the item do decrement.

int $value

Decrement the item by value.

Return Value

int|false

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

bool close()

(PECL memcache >= 0.4.0)
Close memcached server connection

Return Value

bool

Returns TRUE on success or FALSE on failure.

bool flush()

(PECL memcache >= 1.0.0)
Flush all existing items at the server

Return Value

bool

Returns TRUE on success or FALSE on failure.