Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Memcached Configure Options
NameDefaultChangeableChangelog
memcached.sess_lockingOnINI_ALLAvailable as of memcached 0.1.0.
memcached.sess_consistent_hashOnINI_ALLAvailable as of memcached 2.1.0. Default value is On as of memcached 3.0.0.
memcached.sess_binaryOffINI_ALLAvailable as of memcached 2.0.0. Replaced by memcached.sess_binary_protocol as of memcached 3.0.0.
memcached.sess_lock_wait150000INI_ALLAvailable as of memcached 0.1.0. Removed as of memcached 3.0.0.
memcached.sess_prefixmemc.sess.key.INI_ALLAvailable as of memcached 0.1.0.
memcached.sess_number_of_replicas0INI_ALLAvailable as of memcached 2.1.0.
memcached.sess_randomize_replica_readOffINI_ALLAvailable as of memcached 2.1.0.
memcached.sess_remove_failedOnINI_ALLAvailable as of memcached 2.1.0. Replaced by memcached.sess_remove_failed_servers as of memcached 3.0.0.
memcached.compression_typefastlzINI_ALLAvailable as of memcached 0.1.0.
memcached.compression_factor1.3INI_ALLAvailable as of memcached 0.1.0.
memcached.compression_threshold2000INI_ALLAvailable as of memcached 0.1.0.
memcached.serializerigbinaryINI_ALLAvailable as of memcached 0.1.0.
memcached.use_saslOffINI_ALLAvailable as of memcached 2.2.0. Removed as of memcached 3.0.0.
memcached.default_binary_protocolOffINI_ALLAvailable as of memcached 3.0.0.
memcached.default_connect_timeout0INI_ALLAvailable as of memcached 3.0.0.
memcached.default_consistent_hashOffINI_ALLAvailable as of memcached 3.0.0.
memcached.sess_binary_protocolOnINI_ALLAvailable as of memcached 3.0.0. Replace memcached.sess_binary.
memcached.sess_connect_timeout1000INI_ALLAvailable as of memcached 2.2.0.
memcached.sess_consistent_hash_typeketamaINI_ALLAvailable as of memcached 3.1.0.
memcached.sess_lock_expire0INI_ALLAvailable as of memcached 2.2.0.
memcached.sess_lock_retries5INI_ALLAvailable as of memcached 3.0.0.
memcached.sess_lock_wait_max150INI_ALLAvailable as of memcached 3.0.0. Default value 150 as of memcached 3.1.0 (previously 2000).
memcached.sess_lock_wait_min150INI_ALLAvailable as of memcached 3.0.0. Default value 150 as of memcached 3.1.0 (previously 1000).
memcached.sess_persistentOffINI_ALLAvailable as of memcached 3.0.0.
memcached.sess_remove_failed_serversOffINI_ALLAvailable as of memcached 3.0.0. Replace memcached.sess_remove_failed.
memcached.sess_server_failure_limit0INI_ALLAvailable as of memcached 3.0.0.
memcached.sess_sasl_passwordnullINI_ALLAvailable as of memcached 2.2.0.
memcached.sess_sasl_usernamenullINI_ALLAvailable as of memcached 2.2.0.
memcached.store_retry_count0INI_ALL Available as of memcached 2.2.0. Default value 0 as of memcached 3.2.0 (previously 2).

Here's a short explanation of the configuration directives.

memcached.sess_lockingbool

Use session locking. Valid values: On, Off, the default is On.

memcached.sess_consistent_hashbool

If set to On, consistent hashing (libketama) is used for session handling. When consistent hashing is used, one can add or remove cache node(s) without messing up too much with existing keys. Default is On.

memcached.sess_binarybool

Use memcached session binary mode. Libmemcached replicas only work if binary mode is enabled. The default is Off.

memcached.sess_lock_waitint

Session spin lock retry wait time in microseconds. Be careful when setting this value. Valid values are integers, where 0 is interpreted as the default value. Negative values result in a reduces locking to a try lock. The default is 150000.

memcached.sess_prefixstring

Memcached session key prefix. Valid values are strings less than 219 bytes long. The default value is memc.sess.key.

memcached.sess_number_of_replicasint

Write data to a number of additional memcached servers. This is "poor man's HA" as libmemcached calls it. If this value is positive and sess_remove_failed_servers is enabled when a memcached server fails the session will continue to be available from a replica. However, if the failed memcache server becomes available again it will read the session from there which could have old data or no data at all. Default is 0.

memcached.sess_randomize_replica_readbool

Memcached session replica read randomize.

memcached.sess_remove_failedint

Allow failed memcached server to automatically be removed.

memcached.compression_typestring

Set the compression type, valid values are: fastlz, zlib. The default is fastlz.

memcached.compression_factorfloat

Compression factor. Store compressed value only if the compression factor (saving) exceeds the set limit. Store compressed if: plain_len > comp_len * factor. The default value is 1.3 (23% space saving).

memcached.compression_thresholdint

The compression threshold. Do not compress serialized values below this threshold. The default is 2000 bytes.

memcached.serializerstring

Set the default serializer for new memcached objects. Valid values are: php, igbinary, json, json_array, msgpack.

json

Standard PHP JSON encoding. This serializer is fast and compact but only works on UTF-8 encoded data and does not fully implement serializing. See the JSON extension. Available as of memcached 0.2.0.

json_array

As json, but decodes into arrays. Available as of memcached 2.0.0.

php

The standard PHP serializer.

igbinary

A binary serializer. Available as of memcached 0.1.4.

msgpack

A cross-language binary serializer. Available as of memcached 2.2.0.

The default is igbinary if available, then msgpack if available, then php otherwise.

memcached.use_saslbool

Use SASL authentication for connections. Valid values: On, Off. The default is Off.

memcached.default_binary_protocolbool

Sets the default memcached protocol for new connections. (To configure the memcached protocol for connections used by sessions, use memcached.sess_binary_protocol instead.) If set to On, the memcached binary protocol is used by default. If set to Off, the memcached text protocol is used. Default is Off.

memcached.default_connect_timeoutint

Sets the default memcached connection timeout for new connections. (To configure the memcached connection timeout for sessions, use memcached.sess_connect_timeout instead.) In non-blocking mode this changes the value of the timeout. During socket connection in milliseconds. Specifying -1 means an infinite timeout. Specifying 0 means using the memcached library's default connection timeout. Default is 0.

memcached.default_consistent_hashbool

Sets the default for consistent hashing for new connections. (To configure consistent hashing for session connections, use memcached.sess_consistent_hash instead.) If set to On, consistent hashing (libketama) is used for session handling. When consistent hashing is used, one can add or remove cache node(s) without messing up too much with existing keys default is Off.

memcached.sess_binary_protocolbool

Use the memcached binary protocol for memcached sessions instead of the text protocol. libmemcached replicas only work if the binary mode is enabled. However, certain proxies (such as twemproxy) will only work if the binary protocol is disabled. Default is On as of libmemcached 1.0.18. Prior to libmemcached 1.0.18, the default was Off.

Note: In previous versions of php-memcached, this setting was called memcached.sess_binary.

memcached.sess_connect_timeoutint

memcached connect timeout value In non-blocking mode this changes the value of the timeout during socket connection in milliseconds. Specifying -1 means an infinite timeout.

memcached.sess_consistent_hash_typestring

Memcached session consistent hash type. If set to ketama, consistent hashing (libketama) is used for session handling. If set to ketama_weighted, weighted consistent hashing (libketama) is used for session handling. Default is ketama. Prior to php-memcached 3.0, the default was ketama_weighted.

memcached.sess_lock_expireint

The time, in seconds, before a lock should release itself. Setting to 0 results in the default behaviour, which is to use PHP's max_execution_time. Default is 0.

memcached.sess_lock_retriesint

The number of times to retry locking the session lock, not including the first attempt. Default is 5.

memcached.sess_lock_wait_maxint

The maximum time, in milliseconds, to wait between session lock attempts. The default is 150.

memcached.sess_lock_wait_minint

The minimum time, in milliseconds, to wait between session lock attempts. This value is double on each lock retry until memcached.sess_lock_wait_max is reached, after which any further retries will take memcached.sess_lock_wait_max seconds. The default is 150.

memcached.sess_persistentbool

Whether or not to re-use the memcached connections corresponding to the value(s) of session.save_path after the execution of the script ends. Don't use this if certain settings (e.g. SASL settings, sess_binary_protocol) would be overridden between requests. Default is Off.

memcached.sess_remove_failed_serversbool

Allow failed memcached server to automatically be removed. Default is Off.

Note: In previous versions of php-memcached, this setting was called memcached.sess_remove_failed.

memcached.sess_server_failure_limitint

Set this value to enable the server be removed after configured number of continuous times connection failure. Default is 0.

memcached.sess_sasl_passwordstring

Session SASL password. Both username and password need to be set for SASL to be enabled.

memcached.sess_sasl_usernamestring

Session SASL username. Both username and password need to be set for SASL to be enabled.

memcached.store_retry_countint

The amount of retries for failed store commands. This mechanism allows transparent fail-over to secondary servers when set/increment/decrement/setMulti operations fail on the desired server in a multi-server environment. The default is 2.

To Top