From 42743def8d29b7aff978c433a583e422e29a6125 Mon Sep 17 00:00:00 2001 From: Ameir Abdeldayem Date: Mon, 8 Dec 2014 02:55:05 -0500 Subject: [PATCH 1/2] Allow binary protocol to be toggled with Memcached driver. --- wp-ffpc-backend.php | 4 +++- wp-ffpc-class.php | 10 +++++++++- wp-ffpc.php | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/wp-ffpc-backend.php b/wp-ffpc-backend.php index db44de2..c678256 100644 --- a/wp-ffpc-backend.php +++ b/wp-ffpc-backend.php @@ -676,7 +676,9 @@ class WP_FFPC_Backend { /* use binary and not compressed format, good for nginx and still fast */ $this->connection->setOption( Memcached::OPT_COMPRESSION , false ); - $this->connection->setOption( Memcached::OPT_BINARY_PROTOCOL , true ); + if ($this->options['memcached_binary']){ + $this->connection->setOption( Memcached::OPT_BINARY_PROTOCOL , true ); + } if ( version_compare( phpversion( 'memcached' ) , '2.0.0', '>=' ) && ini_get( 'memcached.use_sasl' ) == 1 && isset($this->options['authpass']) && !empty($this->options['authpass']) && isset($this->options['authuser']) && !empty($this->options['authuser']) ) { $this->connection->setSaslAuthData ( $this->options['authuser'], $this->options['authpass']); diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index ceaaba7..b6673fc 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -246,7 +246,7 @@ class WP_FFPC extends PluginAbstract { { $memcache_protocol = strtolower($memcache_settings['memcache.protocol']['local_value']); if ( $memcache_protocol == 'binary' ) { - $this->errors['binary_memcache'] = __('WARNING: Memcache extension is configured to use binary mode. This is very buggy and the plugin will most probably not work correctly.
Please consider to change either to ASCII mode or to Memcached extension.', $this->plugin_constant ); + $this->errors['memcached_binary'] = __('WARNING: Memcache extension is configured to use binary mode. This is very buggy and the plugin will most probably not work correctly.
Please consider to change either to ASCII mode or to Memcached extension.', $this->plugin_constant ); } } } @@ -684,6 +684,14 @@ class WP_FFPC extends PluginAbstract { - in case of TCP based connections, list the servers as host1:port1,host2:port2,... . Do not add trailing , and always separate host and port with : .
- in2.0.0b1 case using unix sockets with the Memcache driver: unix:// ', $this->plugin_constant); ?> +
+ +
+
+ options['memcached_binary'],true); ?> /> + plugin_constant); ?> +
+ options['cache_type'], 'memcached') && extension_loaded ( 'memcached' ) && version_compare( phpversion( 'memcached' ) , '2.0.0', '>=' ) || ( $this->options['cache_type'] == 'redis' ) ) { ?> '127.0.0.1:11211', + 'memcached_binary' => false, 'authpass'=>'', 'authuser'=>'', 'expire'=>300, From 4e647efb2ccfbcd19c9f60f6e73fc18116d1df86 Mon Sep 17 00:00:00 2001 From: Ameir Abdeldayem Date: Mon, 8 Dec 2014 03:35:23 -0500 Subject: [PATCH 2/2] Since Memcached stats aren't available on many implementations, let's check health by doing a set instead. --- wp-ffpc-backend.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wp-ffpc-backend.php b/wp-ffpc-backend.php index c678256..5378a29 100644 --- a/wp-ffpc-backend.php +++ b/wp-ffpc-backend.php @@ -728,14 +728,14 @@ class WP_FFPC_Backend { private function memcached_status () { /* server status will be calculated by getting server stats */ $this->log ( __translate__("checking server statuses", $this->plugin_constant )); - /* get servers statistic from connection */ - $report = $this->connection->getStats(); + /* get server list from connection */ + $servers = $this->connection->getServerList(); - foreach ( $report as $server_id => $details ) { + foreach ( $servers as $server ) { + $server_id = $server['host'] . self::port_separator . $server['port']; /* reset server status to offline */ $this->status[$server_id] = 0; - /* if server uptime is not empty, it's most probably up & running */ - if ( !empty($details['uptime']) ) { + if ($this->connection->set($this->plugin_constant, time())) { $this->log ( sprintf( __translate__( '%s server is up & running', $this->plugin_constant ), $server_id ) ); $this->status[$server_id] = 1; }