all repos — wp-ffpc @ 238d54a194acc41c150db8be0b841cd0fbe93661

Merge pull request #29 from ameir/compatibility

Memcached proxy compatibility
Peter Molnar hello@petermolnar.eu
Mon, 08 Dec 2014 09:37:26 +0000
commit

238d54a194acc41c150db8be0b841cd0fbe93661

parent

eb4942005273822aec8c2da09f0e763807f94f9c

3 files changed, 18 insertions(+), 7 deletions(-)

jump to
M wp-ffpc-backend.phpwp-ffpc-backend.php

@@ -676,7 +676,9 @@ $this->connection = new Memcached();

/* 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']);

@@ -726,14 +728,14 @@ */

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; }
M wp-ffpc-class.phpwp-ffpc-class.php

@@ -246,7 +246,7 @@ if ( !empty ( $memcache_settings ) && $this->options['cache_type'] == 'memcache' )

{ $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. <br />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. <br />Please consider to change either to ASCII mode or to Memcached extension.', $this->plugin_constant ); } } }

@@ -687,6 +687,14 @@ <span class="description">

<?php _e('List of backends, with the following syntax: <br />- 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 : .<br />- in2.0.0b1 case using unix sockets with the Memcache driver: unix:// ', $this->plugin_constant); ?></span> </dd> + <dt> + <label for="memcached_binary"><?php _e('Enable memcached binary mode', $this->plugin_constant); ?></label> + </dt> + <dd> + <input type="checkbox" name="memcached_binary" id="memcached_binary" value="1" <?php checked($this->options['memcached_binary'],true); ?> /> + <span class="description"><?php _e('Some memcached proxies and implementations only support the ASCII protocol.', $this->plugin_constant); ?></span> + </dd> + <?php if ( strstr ( $this->options['cache_type'], 'memcached') && extension_loaded ( 'memcached' ) && version_compare( phpversion( 'memcached' ) , '2.0.0', '>=' ) || ( $this->options['cache_type'] == 'redis' ) ) { ?> <?php
M wp-ffpc.phpwp-ffpc.php

@@ -29,6 +29,7 @@ include_once ( 'wp-ffpc-class.php' );

$wp_ffpc_defaults = array ( 'hosts'=>'127.0.0.1:11211', + 'memcached_binary' => false, 'authpass'=>'', 'authuser'=>'', 'expire'=>300,