Configuration à l'exécution

Le comportement de ces fonctions est affecté par la configuration dans le fichier php.ini.

Memcached Options de configuration
Nom Défaut Modifiable Historique
memcached.sess_locking On INI_ALL Available as of memcached 0.1.0.
memcached.sess_consistent_hash On INI_ALL Available as of memcached 2.1.0. Default value is On as of memcached 3.0.0.
memcached.sess_binary Off INI_ALL Available as of memcached 2.0.0. Replaced by memcached.sess_binary_protocol as of memcached 3.0.0.
memcached.sess_lock_wait 150000 INI_ALL Available as of memcached 0.1.0. Removed as of memcached 3.0.0.
memcached.sess_prefix memc.sess.key. INI_ALL Available as of memcached 0.1.0.
memcached.sess_number_of_replicas 0 INI_ALL Available as of memcached 2.1.0.
memcached.sess_randomize_replica_read Off INI_ALL Available as of memcached 2.1.0.
memcached.sess_remove_failed On INI_ALL Available as of memcached 2.1.0. Replaced by memcached.sess_remove_failed_servers as of memcached 3.0.0.
memcached.compression_type fastlz INI_ALL Available as of memcached 0.1.0.
memcached.compression_factor 1.3 INI_ALL Available as of memcached 0.1.0.
memcached.compression_threshold 2000 INI_ALL Available as of memcached 0.1.0.
memcached.serializer igbinary INI_ALL Available as of memcached 0.1.0.
memcached.use_sasl Off INI_ALL Available as of memcached 2.2.0. Removed as of memcached 3.0.0.
memcached.default_binary_protocol Off INI_ALL Available as of memcached 3.0.0.
memcached.default_connect_timeout 0 INI_ALL Available as of memcached 3.0.0.
memcached.default_consistent_hash Off INI_ALL Available as of memcached 3.0.0.
memcached.sess_binary_protocol On INI_ALL Available as of memcached 3.0.0. Replace memcached.sess_binary.
memcached.sess_connect_timeout 1000 INI_ALL Available as of memcached 2.2.0.
memcached.sess_consistent_hash_type ketama INI_ALL Available as of memcached 3.1.0.
memcached.sess_lock_expire 0 INI_ALL Available as of memcached 2.2.0.
memcached.sess_lock_retries 5 INI_ALL Available as of memcached 3.0.0.
memcached.sess_lock_wait_max 150 INI_ALL Available as of memcached 3.0.0. Default value 150 as of memcached 3.1.0 (previously 2000).
memcached.sess_lock_wait_min 150 INI_ALL Available as of memcached 3.0.0. Default value 150 as of memcached 3.1.0 (previously 1000).
memcached.sess_persistent Off INI_ALL Available as of memcached 3.0.0.
memcached.sess_remove_failed_servers Off INI_ALL Available as of memcached 3.0.0. Replace memcached.sess_remove_failed.
memcached.sess_server_failure_limit 0 INI_ALL Available as of memcached 3.0.0.
memcached.sess_sasl_password null INI_ALL Available as of memcached 2.2.0.
memcached.sess_sasl_username null INI_ALL Available as of memcached 2.2.0.
memcached.store_retry_count 0 INI_ALL Available as of memcached 2.2.0. Default value 0 as of memcached 3.2.0 (previously 2).

Voici un éclaircissement sur l'utilisation des directives de configuration.

memcached.sess_locking bool

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

memcached.sess_consistent_hash bool

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_binary bool

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

memcached.sess_lock_wait int

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_prefix string

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

memcached.sess_number_of_replicas int

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_read bool

Memcached session replica read randomize.

memcached.sess_remove_failed int

Allow failed memcached server to automatically be removed.

memcached.compression_type string

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

memcached.compression_factor float

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_threshold int

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

memcached.serializer string

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_sasl bool

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

memcached.default_binary_protocol bool

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_timeout int

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_hash bool

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_protocol bool

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_timeout int

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_type string

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_expire int

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_retries int

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

memcached.sess_lock_wait_max int

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

memcached.sess_lock_wait_min int

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_persistent bool

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_servers bool

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_limit int

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

memcached.sess_sasl_password string

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

memcached.sess_sasl_username string

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

memcached.store_retry_count int

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.

add a note add a note

User Contributed Notes 3 notes

up
3
senz
10 years ago
In case, you are wondering why your sessions are "killed" after 1440 seconds, take a look at session.gc_maxlifetime. It's value is used in memcached expiration field according to memcache protocol rules. Also, do not forget about cookie expiration time
up
0
Piotr Gabryjeluk
7 years ago
Apparently in version 3.0.3 the default for memcached.sess_binary_protocol in TRUE. Also note the key is memcached.sess_binary_protocol, not memcached.sess.

Setting memcached.sess_binary_protocol to FALSE is required if you want to save the session to memcached through twemproxy.
up
-1
adolfoabegg at gmail dot com
12 years ago
you can get the list of the possible options for the memcached.ini configuration file here:
https://github.com/php-memcached-dev/php-memcached/blob/master/memcached.ini
To Top