From 180ad0f2bf3446dc77ac7a9bdd95a5ff59141423 Mon Sep 17 00:00:00 2001 From: cadeyrn Date: Tue, 21 Feb 2012 06:39:19 +0000 Subject: [PATCH] bugfix, version v0.2.2 git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@508069 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- readme.txt | 9 +++++--- wp-ffpc-common.php | 55 ++++++++++++++++++++++++++-------------------- wp-ffpc.php | 11 ++++------ 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/readme.txt b/readme.txt index 236291a..b4e9143 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: cadeyrn Tags: cache, APC, memcached, full page cache Requires at least: 3.0 Tested up to: 3.3.1 -Stable tag: 0.2.1 +Stable tag: 0.2.2 Fast Full Page Cache, backend can be memcached or APC @@ -46,18 +46,21 @@ Some parts were based on [Hyper Cache](http://wordpress.org/extend/plugins/hyper == Changelog == += 0.2.2 = +2012.02.21 + +* memcache types bugfix, reported in forum, thanks! + = 0.2.1 = 2012.02.21 * bugfix, duplicated inclusion could emerge, fix added, thanks for Géza Kuti for reporting! - = 0.2 = 2012.02.19 * added APC compression option ( requires PHP ZLIB ). Useful is output pages are large. Compression is on lowest level, therefore size/CPU load is more or less optimal. - = 0.1 = 2012.02.16 diff --git a/wp-ffpc-common.php b/wp-ffpc-common.php index 494f989..84bdc83 100644 --- a/wp-ffpc-common.php +++ b/wp-ffpc-common.php @@ -20,18 +20,15 @@ if ( function_exists('wp_ffpc_init') || function_exists('wp_ffpc_clear') || func * if false, backend will be globally initiated * when set, backend will not become global, just tested if alive */ -function wp_ffpc_init( $type = false ) { - global $wp_ffpc_config; +function wp_ffpc_init( $wp_ffpc_config ) { + global $wp_ffpc_backend; $wp_ffpc_backend_status = false; - $reg_backend = $type; - // $type is to test an exact backend */ - if ( !$type ) - $type = $wp_ffpc_config['cache_type']; - + if ( empty ( $wp_ffpc_config )) + global $wp_ffpc_config; /* verify selected storage is available */ - switch ($type) + switch ( $wp_ffpc_config['cache_type'] ) { /* in case of apc */ case 'apc': @@ -49,10 +46,11 @@ function wp_ffpc_init( $type = false ) { /* Memcache class does not exist, Memcache extension is not available */ if (!class_exists('Memcache')) return false; - if ($reg_backend) - global $wp_ffpc_backend; - $wp_ffpc_backend = new Memcache(); - $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + if ( $wp_ffpc_backend == NULL ) + { + $wp_ffpc_backend = new Memcache(); + $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + } $wp_ffpc_backend_status = $wp_ffpc_backend->getServerStatus( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); break; @@ -61,10 +59,11 @@ function wp_ffpc_init( $type = false ) { /* Memcached class does not exist, Memcached extension is not available */ if (!class_exists('Memcached')) return false; - if ($reg_backend) - global $wp_ffpc_backend; - $wp_ffpc_backend = new Memcached(); - $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + if ( $wp_ffpc_backend == NULL ) + { + $wp_ffpc_backend = new Memcached(); + $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + } $wp_ffpc_backend_status = array_key_exists( $wp_ffpc_config['host'] . ':' . $wp_ffpc_config['port'] , $wp_ffpc_backend->getStats() ); break; @@ -143,6 +142,7 @@ function wp_ffpc_clear ( $post_id = false ) { */ function wp_ffpc_set ( &$key, &$data, $compress = false ) { global $wp_ffpc_config; + global $wp_ffpc_backend; switch ($wp_ffpc_config['cache_type']) { @@ -150,16 +150,20 @@ function wp_ffpc_set ( &$key, &$data, $compress = false ) { /* use apc_store to overwrite data is existed */ if ( $compress ) $data = gzdeflate ( $data , 1 ); - apc_store( $key , $data , $wp_ffpc_config['expire']); + return apc_store( $key , $data , $wp_ffpc_config['expire']); break; case 'memcache': - global $wp_ffpc_backend; - /* false to disable compression, vital for nginx */ - $wp_ffpc_backend->set ( $key, $data , false, $wp_ffpc_config['expire'] ); + if ( $wp_ffpc_backend != NULL ) + /* false to disable compression, vital for nginx */ + $wp_ffpc_backend->set ( $key, $data , false, $wp_ffpc_config['expire'] ); + else + return false; break; case 'memcached': - global $wp_ffpc_backend; - $wp_ffpc_backend->set ( $key, $data , $wp_ffpc_config['expire'] ); + if ( $wp_ffpc_backend != NULL ) + $wp_ffpc_backend->set ( $key, $data , $wp_ffpc_config['expire'] ); + else + return false; break; } } @@ -172,6 +176,7 @@ function wp_ffpc_set ( &$key, &$data, $compress = false ) { */ function wp_ffpc_get( &$key , $uncompress = false ) { global $wp_ffpc_config; + global $wp_ffpc_backend; switch ($wp_ffpc_config['cache_type']) { @@ -182,8 +187,10 @@ function wp_ffpc_get( &$key , $uncompress = false ) { return $value; case 'memcache': case 'memcached': - global $wp_ffpc_backend; - return $wp_ffpc_backend->get($key); + if ( $wp_ffpc_backend != NULL ) + return $wp_ffpc_backend->get($key); + else + return false; default: return false; } diff --git a/wp-ffpc.php b/wp-ffpc.php index eefeef5..a019c7d 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -1,7 +1,7 @@ get_options(); /* check is backend is available */ - $alive = wp_ffpc_init( $this->options['cache_type'] ); + $alive = wp_ffpc_init( $this->options ); /* don't register hooks if backend is dead */ if ($alive) @@ -328,12 +328,9 @@ if (!class_exists('WPFFPC')) {
options); - $server_status = ( $server_status ) ? 'down' : 'up & running' ; + $server_status = ( empty($server_status) || $server_status == 0 ) ? 'down' : 'up & running' ; echo $server_status; ?>