diff --git a/advanced-cache.php b/advanced-cache.php index 98cfe7d..2b71dd1 100644 --- a/advanced-cache.php +++ b/advanced-cache.php @@ -14,7 +14,7 @@ if (!isset($wp_ffpc_config)) /* request uri */ $wp_ffpc_uri = $_SERVER['REQUEST_URI']; /* query string */ -$wp_ffpc_qs = strpos($wp_ffpc_uri, '?'); +$wp_ffpc_qs = stripos($wp_ffpc_uri, '?'); /* no cache for uri with query strings, things usually go bad that way */ if ($wp_ffpc_qs !== false) @@ -32,15 +32,15 @@ if (defined('SID') && SID != '') return false; /* no cache for pages starting with /wp- like WP admin */ -if (strpos($wp_ffpc_uri, '/wp-') !== false) +if (stripos($wp_ffpc_uri, '/wp-') !== false) return false; /* no cache for robots.txt */ -if ( strpos($wp_ffpc_uri, 'robots.txt') ) +if ( stripos($wp_ffpc_uri, 'robots.txt') ) return false; /* multisite files can be too large for memcached */ -if (function_exists('is_multisite') && is_multisite() && strpos($wp_ffpc_uri, '/files/') ) +if (function_exists('is_multisite') && is_multisite() && stripos($wp_ffpc_uri, '/files/') ) return false; @@ -179,7 +179,7 @@ function wp_ffpc_callback($buffer) { return $buffer; /* no close tag = not HTML, don't cache */ - if (strpos($buffer, '') === false) + if (stripos($buffer, '') === false) return $buffer; /* reset meta to solve conflicts */ @@ -217,6 +217,7 @@ function wp_ffpc_callback($buffer) { $nocache_key = 'nocache_'. $wp_ffpc_meta['type']; if ( $wp_ffpc_config[$nocache_key] == 1 ) { + wp_ffpc_log ( "not caching, prevented by settings for no-cache: " . $nocache_key ); return $buffer; } @@ -273,18 +274,6 @@ function wp_ffpc_callback($buffer) { /* set meta */ wp_ffpc_set ( $wp_ffpc_meta_key, $wp_ffpc_meta ); - - /* set meta per entry for nginx */ - /* - foreach ( $wp_ffpc_meta as $subkey => $subdata ) - { - $subkey = str_replace ( $wp_ffpc_config['prefix_meta'], $wp_ffpc_config['prefix_meta'] . $subkey . "-", $wp_ffpc_meta_key ); - wp_ffpc_set ( $subkey, $subdata ); - } - */ - - /* set data */ - //$data = $buffer; wp_ffpc_set ( $wp_ffpc_data_key, $buffer, $compress ); /* vital for nginx, make no problem at other places */ diff --git a/readme.txt b/readme.txt index df4bc8d..f909c9c 100644 --- a/readme.txt +++ b/readme.txt @@ -1,6 +1,6 @@ === WP-FFPC === Contributors: cadeyrn -Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=8LZ66LGFLMKJW&lc=HU&item_name=Peter%20Molnar%20photographer%2fdeveloper&item_number=petermolnar%2dpaypal%2ddonation¤cy_code=USD&bn=PP%2dDonationsBF%3acredit%2epng%3aNonHosted +Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC Tags: cache, APC, memcached, full page cache Requires at least: 3.0 Tested up to: 3.5.1 @@ -59,9 +59,16 @@ You have to remove the default yum package, named `php-pecl-memcache` and instal = 0.5 = 2013.03.04 +WARNING, MAJOR CHANGES! + * long-running %3C really fixed ( version 0.4.3 was dead end ) by the help of Mark Costlow -* UI cleanup + tabs -* WP-FFPC options moved from global under Settings ( of either network or site ) +* UI cleanup, introducing tabbed interface +* WP-FFPC options moved from global menu to under Settings in both Site and Network Admin interfaces +* added 'persistent' checkbox for memcached connections +* added possibility to add multiple memcached servers +* case-sensitive string checks replaced with case-insensitives, contribution of Mark Costlow +* refactored settings saving mechanism +* additional syslog informations = 0.4.3 = 2013.03.03 diff --git a/wp-ffpc-common.php b/wp-ffpc-common.php index 94fc216..1de6721 100644 --- a/wp-ffpc-common.php +++ b/wp-ffpc-common.php @@ -58,9 +58,15 @@ function wp_ffpc_init( $wp_ffpc_config ) { if ( $wp_ffpc_backend == NULL ) { $wp_ffpc_backend = new Memcache(); - $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + 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'] ); + } } - $wp_ffpc_backend_status = $wp_ffpc_backend->getStats( ); break; /* in case of Memcached */ @@ -70,12 +76,27 @@ function wp_ffpc_init( $wp_ffpc_config ) { return false; if ( $wp_ffpc_backend == NULL ) { - $wp_ffpc_backend = new Memcached(); + if ( $wp_ffpc_config['persistent'] == '1' ) + $wp_ffpc_backend = new Memcached( WP_FFPC_PARAM ); + else + $wp_ffpc_backend = new Memcached(); + $wp_ffpc_backend->setOption( Memcached::OPT_COMPRESSION , false ); $wp_ffpc_backend->setOption( Memcached::OPT_BINARY_PROTOCOL , true ); - $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + $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; + } } - $wp_ffpc_backend_status = array_key_exists( $wp_ffpc_config['host'] . ':' . $wp_ffpc_config['port'] , $wp_ffpc_backend->getStats() ); break; /* cache type is invalid */ @@ -243,7 +264,7 @@ function wp_ffpc_log ( $string ) { /* syslog */ if ($wp_ffpc_config['syslog'] && function_exists('syslog') ) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . $string . WP_FFPC_LOG_TYPE_MSG ); + syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM .": " . $string . WP_FFPC_LOG_TYPE_MSG ); } ?> diff --git a/wp-ffpc.php b/wp-ffpc.php index 8b1bf14..17b7eea 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -61,6 +61,8 @@ define ( 'WP_FFPC_ACACHE_MAIN_FILE' , ABSPATH . 'wp-content/advanced-cache.php' define ( 'WP_FFPC_ACACHE_INC_FILE' , WP_FFPC_DIR. '/advanced-cache.php' ); define ( 'WP_FFPC_ACACHE_COMMON_FILE' , WP_FFPC_DIR. '/wp-ffpc-common.php' ); define ( 'WP_FFPC_CONFIG_VAR' , '$wp_ffpc_config' ); +define ( 'WP_FFPC_SERVER_LIST_SEPARATOR' , ',' ); +define ( 'WP_FFPC_SERVER_SEPARATOR', ':' ); include_once (WP_FFPC_DIR .'/wp-ffpc-common.php'); @@ -201,6 +203,8 @@ if (!class_exists('WPFFPC')) {
+

This plugin helped your business? Buy me a coffee for having it :)

+

@@ -219,15 +223,25 @@ if (!class_exists('WPFFPC')) { options['cache_type'] == 'memcached' || $this->options['cache_type'] == 'memcache' ) : ?> -

+

+

options['host'] . ', port ' . $this->options['port'] .' with driver "' . $this->options['cache_type'] . '": ', WP_FFPC_PARAM ); - $server_status = wp_ffpc_init( $this->options); - - $server_status = ( empty($server_status) || $server_status == 0 ) ? 'down' : 'up & running' ; - echo $server_status; + _e ( 'Driver: ' , WP_FFPC_PARAM); + echo $this->options['cache_type']; ?> -

+

+

+ Backend status:
', WP_FFPC_PARAM ); + $init = wp_ffpc_init( $this->options); + 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"; + } + ?> +

+

@@ -425,21 +439,20 @@ if (!class_exists('WPFFPC')) {
- +
- - + + : defaults['host']; ?>
-
- +
- - - : defaults['port']; ?> + options['persistent'],true); ?> /> + + : defaults['persistent']; ?>
@@ -556,15 +569,9 @@ if (!class_exists('WPFFPC')) { if ( @file_exists( $acache )) return false; - $string = 'options as $key => $val) { - if (is_string($val)) - $val = "'" . $val . "'"; - - $string .= WP_FFPC_CONFIG_VAR . '[\'' . $key . '\']=' . $val . ";\n"; - } + $string .= WP_FFPC_CONFIG_VAR .' = ' .var_export( $this->options , true ) . ';'; $string .= "\n\ninclude_once ('" . WP_FFPC_ACACHE_COMMON_FILE . "');\ninclude_once ('" . WP_FFPC_ACACHE_INC_FILE . "');\n"; @@ -572,14 +579,14 @@ if (!class_exists('WPFFPC')) { return true; } + /** * parameters array with default values; * */ function get_options ( ) { $defaults = array ( - 'port'=>11211, - 'host'=>'127.0.0.1', + 'hosts'=>'127.0.0.1:11211', 'expire'=>300, 'invalidation_method'=>0, 'prefix_meta' =>'meta-', @@ -597,11 +604,19 @@ if (!class_exists('WPFFPC')) { 'nocache_page' => false, 'apc_compress' => false, 'sync_protocols' => false, + 'persistent' => false, + 'servers' => array ( + 'host' => '127.0.0.1', + 'port' => 11211 + ), ); $this->defaults = $defaults; $this->options = get_site_option( WP_FFPC_PARAM , $defaults, false ); + + $this->split_hosts(); + } /** @@ -667,28 +682,31 @@ if (!class_exists('WPFFPC')) { */ function save_settings ( $firstrun = false ) { - /** - * update params from $_POST - */ - foreach ($this->options as $name=>$optionvalue) + $defaults = $this->defaults; + + foreach ( $defaults as $key => $default ) { - if (!empty($_POST[$name])) + if (!empty($_POST[$key])) { - $update = $_POST[$name]; - if (strlen($update)!=0 && !is_numeric($update)) + $update = $_POST[$key]; + if ( strlen( $update ) !=0 && !is_numeric($update) ) $update = stripslashes($update); } - elseif ( ( empty($_POST[$name]) && is_bool ($this->defaults[$name]) ) || is_int( $this->defaults[$name] ) ) + elseif ( ( empty( $_POST[$name] ) && is_bool ( $default ) ) || is_int( $default ) ) { $update = 0; } else { - $update = $this->defaults[$name]; + $update = $this->options[$key]; } - $this->options[$name] = $update; + + $options[$key] = $update; } + $this->options = $options; + $this->split_hosts(); + update_site_option( WP_FFPC_PARAM , $this->options ); $this->invalidate('system_flush'); @@ -698,6 +716,28 @@ if (!class_exists('WPFFPC')) { } + function split_hosts ( ) { + + $servers = explode( WP_FFPC_SERVER_LIST_SEPARATOR , $this->options['hosts']); + $good_servers = array(); + + foreach ( $servers as $server_num => $server_string ) { + $separator = strpos( $server_string , WP_FFPC_SERVER_SEPARATOR ); + $host = substr( $server_string, 0, $separator ); + $port = substr( $server_string, $separator + 1 ); + + if ( !empty ( $host ) && !empty($port) && is_numeric($port) ) { + $good_servers[$server_string] = array ( + 'host' => $host, + 'port' => $port + ); + } + } + + if ( !empty ( $good_servers )) + $this->options['servers'] = $good_servers; + } + /** * clean up at uninstall *