From ad7a968fb025fe3d90e527a6e8c327c72bb093b3 Mon Sep 17 00:00:00 2001 From: Matthew Flaschen Date: Wed, 24 Aug 2016 14:56:39 -0400 Subject: [PATCH] Memcached PECL: Allow using binary protocol This is required for e.g. the touch() method in older versions of the Memcached client. It still defaults to ASCII. Bug: T143464 Change-Id: Ib6b22b47fddc3dbad885f86c31eb1571df0438ff --- .../objectcache/MemcachedPeclBagOStuff.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/includes/objectcache/MemcachedPeclBagOStuff.php b/includes/objectcache/MemcachedPeclBagOStuff.php index bb760bd383..aefda7994c 100644 --- a/includes/objectcache/MemcachedPeclBagOStuff.php +++ b/includes/objectcache/MemcachedPeclBagOStuff.php @@ -42,6 +42,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { * - serializer: May be either "php" or "igbinary". Igbinary produces more compact * values, but serialization is much slower unless the php.ini option * igbinary.compact_strings is off. + * - use_binary_protocol Whether to enable the binary protocol (default is ASCII) (boolean) * @param array $params * @throws InvalidArgumentException */ @@ -62,8 +63,8 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { $this->client = new Memcached; } - if ( !isset( $params['serializer'] ) ) { - $params['serializer'] = 'php'; + if ( $params['use_binary_protocol'] ) { + $this->client->setOption( Memcached::OPT_BINARY_PROTOCOL, true ); } if ( isset( $params['retry_timeout'] ) ) { @@ -119,6 +120,20 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { $this->client->addServers( $servers ); } + protected function applyDefaultParams( $params ) { + $params = parent::applyDefaultParams( $params ); + + if ( !isset( $params['use_binary_protocol'] ) ) { + $params['use_binary_protocol'] = false; + } + + if ( !isset( $params['serializer'] ) ) { + $params['serializer'] = 'php'; + } + + return $params; + } + protected function getWithToken( $key, &$casToken, $flags = 0 ) { $this->debugLog( "get($key)" ); $result = $this->client->get( $this->validateKeyEncoding( $key ), null, $casToken ); -- 2.20.1