From 4310614a3c3200b9b3be6b6769878ab9a10cfc07 Mon Sep 17 00:00:00 2001 From: cadeyrn Date: Fri, 8 Mar 2013 11:19:34 +0000 Subject: [PATCH] version 0.6.1 git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@677998 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- readme.txt | 9 +++++-- wp-ffpc-common.php | 67 +++++++++++++++++++++++++++++++++------------- wp-ffpc.php | 21 +++++++++++---- 3 files changed, 72 insertions(+), 25 deletions(-) diff --git a/readme.txt b/readme.txt index fc9b650..22df308 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i Tags: cache, APC, memcache, memcached, page cache, full page cache, nginx Requires at least: 3.0 Tested up to: 3.5.1 -Stable tag: 0.5.1 +Stable tag: 0.6.1 Store WordPress pages in memcached and serve them with nginx - unbeatable speed! @@ -56,8 +56,13 @@ You have to remove the default yum package, named `php-pecl-memcache` and instal == Changelog == += 0.6.1 = +*2013.03.08* + +* refactored & corrected backend status check for memcached driver + = 0.6 = -*development branch* +*2013.03.08* * true WordPress Network support: * if enabled network-wide, settings will be the same for every site diff --git a/wp-ffpc-common.php b/wp-ffpc-common.php index 070e070..0847b59 100644 --- a/wp-ffpc-common.php +++ b/wp-ffpc-common.php @@ -56,17 +56,20 @@ function wp_ffpc_init( $wp_ffpc_config ) { if (!class_exists('Memcache')) return false; if ( $wp_ffpc_backend == NULL ) - { $wp_ffpc_backend = new Memcache(); - foreach ( $wp_ffpc_config['servers'] as $server_id => $server ) { - $wp_ffpc_backend_status[$server_id] = $wp_ffpc_backend->connect( $server['host'] , $server['port'] ); - $wp_ffpc_config['persistent'] = ( $wp_ffpc_config['persistent'] == '1' ) ? true : false; - if ( $wp_ffpc_backend_status[$server_id] ) - $wp_ffpc_backend->addServer( $server['host'] , $server['port'], $wp_ffpc_config['persistent'] ); - wp_ffpc_log ( "server " . $server_id . " added, persistent mode: " . $wp_ffpc_config['persistent'] ); + foreach ( $wp_ffpc_config['servers'] as $server_id => $server ) { + $wp_ffpc_backend_status[$server_id] = $wp_ffpc_backend->connect( $server['host'] , $server['port'] ); + + $wp_ffpc_config['persistent'] = ( $wp_ffpc_config['persistent'] == '1' ) ? true : false; + if ( $wp_ffpc_backend_status[$server_id] ) + { + $wp_ffpc_backend_status[$server_id] = true; + $wp_ffpc_backend->addServer( $server['host'] , $server['port'], $wp_ffpc_config['persistent'] ); + wp_ffpc_log ( "server " . $server_id . " added, persistent mode: " . $wp_ffpc_config['persistent'] ); } } + return $wp_ffpc_backend_status; break; /* in case of Memcached */ @@ -74,34 +77,62 @@ function wp_ffpc_init( $wp_ffpc_config ) { /* Memcached class does not exist, Memcached extension is not available */ if (!class_exists('Memcached')) return false; + /* check is there's no backend connection yet */ if ( $wp_ffpc_backend == NULL ) { + /* persistent backend needs an identifier */ if ( $wp_ffpc_config['persistent'] == '1' ) $wp_ffpc_backend = new Memcached( WP_FFPC_PARAM ); else $wp_ffpc_backend = new Memcached(); + /* use binary and not compressed format, good for nginx and still fast */ $wp_ffpc_backend->setOption( Memcached::OPT_COMPRESSION , false ); $wp_ffpc_backend->setOption( Memcached::OPT_BINARY_PROTOCOL , true ); - $wp_ffpc_serverlist = $wp_ffpc_backend->getServerList(); - - if ( empty ( $wp_ffpc_serverlist ) ) - $wp_ffpc_backend->addServers( $wp_ffpc_config['servers'] ); - wp_ffpc_log ( "servers added, persistent mode: " . $wp_ffpc_config['persistent'] ); } - $wp_ffpc_backend_report = $wp_ffpc_backend->getStats(); - foreach ( $wp_ffpc_config['servers'] as $server_id => $server ) { - $wp_ffpc_backend_status[$server_id] = false; - if ( array_key_exists( $server_id, $wp_ffpc_backend_report ) && $wp_ffpc_backend_report[ $server_id ]['pid'] != -1 ) { - $wp_ffpc_backend_status[$server_id] = true; + /* check if we already have list of servers, only add server if it's not already connected */ + $wp_ffpc_serverlist = $wp_ffpc_backend->getServerList(); + + /* create check array if backend servers are already connected */ + if ( !empty ( $wp_ffpc_serverlist ) ) + foreach ( $wp_ffpc_serverlist as $server ) + $wp_ffpc_serverlist_[ $server['host'] . ":" . $server['port'] ] = true; + + /* reset all configured server status to unknown */ + foreach ( $wp_ffpc_config['servers'] as $server_id => $server ) + $wp_ffpc_backend_status[$server_id] = -1; + + /* if there's no server to add, don't add them */ + if ( empty ( $wp_ffpc_config['servers'] ) ) + { + wp_ffpc_log ( "not adding empty set of servers, please check your settings!" ); + } + else + { + foreach ( $wp_ffpc_config['servers'] as $server_id => $server ) { + if (!@array_key_exists($server_id , $wp_ffpc_serverlist_ )) + { + $wp_ffpc_backend->addServer( $server['host'], $server['port'] ); + wp_ffpc_log ( "server ". $server_id ." added, persistent mode: " . $wp_ffpc_config['persistent'] ); + } } } + + /* server status will be calculated by getting server stats */ + $wp_ffpc_backend_report = $wp_ffpc_backend->getStats(); + foreach ( $wp_ffpc_backend_report as $server_id => $server ) { + $wp_ffpc_backend_status[$server_id] = false; + /* if server uptime is not empty, it's most probably up & running */ + if ( !empty($server['uptime']) ) + $wp_ffpc_backend_status[$server_id] = true; + } + break; /* cache type is invalid */ default: - return false; + break; } return ( empty ( $wp_ffpc_backend_status ) ? false : $wp_ffpc_backend_status ); diff --git a/wp-ffpc.php b/wp-ffpc.php index a2f4a8b..10959e4 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -1,7 +1,7 @@ all_options['version'] < WP_FFPC_VERSION ) { + $this->save_settings (); + if ( @file_exists( WP_FFPC_ACACHE_MAIN_FILE )) { + $this->generate_config(); + } + } } /** @@ -291,8 +298,12 @@ if (!class_exists('WPFFPC')) { /* we need to go through all servers */ foreach ( $this->options['servers'] as $server_string => $server ) { echo $server['host'] . ":" . $server['port'] ." => "; - $server_status = ( empty($init) || $init[$server_string] == 0 ) ? 'down' : 'up & running' ; - echo $server_status ."
\n"; + if ( is_array($init) && $init[$server_string] === false ) + _e ( 'down
', WP_FFPC_PARAM ); + elseif ( is_array($init) && $init[$server_string] === true ) + _e ( 'up & running
', WP_FFPC_PARAM ); + else + _e ( 'unknown, please try re-saving settings!
', WP_FFPC_PARAM ); } ?>

@@ -686,7 +697,7 @@ if (!class_exists('WPFFPC')) { 'prefix_data' =>'data-', 'charset' => 'utf-8', 'pingback_status'=> false, - 'debug' => true, + 'debug' => false, 'syslog' => false, 'cache_type' => 'memcached', 'cache_loggedin' => false,