tons o' changes; persistent connections, stripos, new settings save mechanism, etc. git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@676875 b8457f37-d9ea-0310-8a92-e5e31aec5664
@@ -14,7 +14,7 @@
/* 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 @@ if (!function_exists('is_home'))
return $buffer; /* no <body> close tag = not HTML, don't cache */ - if (strpos($buffer, '</body>') === false) + if (stripos($buffer, '</body>') === false) return $buffer; /* reset meta to solve conflicts */@@ -217,6 +217,7 @@ /* check if caching is disabled for page type */
$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 @@ }
/* 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 */
@@ -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 @@
= 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 <cheeks@swcp.com> -* 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 <cheeks@swcp.com> +* refactored settings saving mechanism +* additional syslog informations = 0.4.3 = 2013.03.03
@@ -58,9 +58,15 @@ return false;
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 @@ if (!class_exists('Memcached'))
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 @@ global $wp_ffpc_config;
/* 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 ); } ?>
@@ -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 @@ </script>
<div class="wrap"> + <h4>This plugin helped your business? <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC">Buy me a coffee for having it :)</a></h4> + <?php if ( !WP_CACHE ) : ?> <div class="updated settings-error"><p><strong><?php _e("WARNING: WP_CACHE is disabled, plugin will not work that way. Please add define( 'WP_CACHE', true ); into the beginning of wp-config.php", WP_FFPC_PARAM); ?></strong></p></div> <?php endif; ?>@@ -219,15 +223,25 @@ <div class="updated settings-error"><p><strong><?php _e('WARNING: Memcache extension is configured to use binary mode. This is very buggy and the plugin will most probably not work. Please consider to change either to ascii mode or to Mecached extension.', WP_FFPC_PARAM); ?></strong></p></div>
<?php endif; ?> <?php if ( $this->options['cache_type'] == 'memcached' || $this->options['cache_type'] == 'memcache' ) : ?> - <div class="updated settings-error"><p><strong> + <div class="updated settings-error"> + <p><strong> <?php - _e( 'Backend status on host ' . $this->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 ) ? '<span class="error-msg">down</span>' : '<span class="ok-msg">up & running</span>' ; - echo $server_status; + _e ( 'Driver: ' , WP_FFPC_PARAM); + echo $this->options['cache_type']; ?> - </strong></p></div> + </strong></p> + <p> + <?php + _e( '<strong>Backend status:</strong><br />', 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 ) ? '<span class="error-msg">down</span>' : '<span class="ok-msg">up & running</span>' ; + echo $server_status ."<br />\n"; + } + ?> + </p> + </div> <?php endif; ?> <h2><?php _e( 'WP-FFPC settings', WP_FFPC_PARAM ) ; ?></h2>@@ -425,21 +439,20 @@ <fieldset id="wp-ffpc-memcached">
<legend><?php _e('Settings for memcached backend', WP_FFPC_PARAM); ?></legend> <dl> <dt> - <label for="host"><?php _e('Host', WP_FFPC_PARAM); ?></label> + <label for="host"><?php _e('Host:Port', WP_FFPC_PARAM); ?></label> </dt> <dd> - <input type="text" name="host" id="host" value="<?php echo $this->options['host']; ?>" /> - <span class="description"><?php _e('Hostname for memcached server', WP_FFPC_PARAM); ?></span> + <input type="text" name="hosts" id="hosts" value="<?php echo $this->options['hosts']; ?>" /> + <span class="description"><?php _e('List all valid Hostname:Port[,Hostname:Port] for memcached server(s)', WP_FFPC_PARAM); ?></span> <span class="default"><?php _e('Default ', WP_FFPC_PARAM); ?>: <?php echo $this->defaults['host']; ?></span> </dd> - <dt> - <label for="port"><?php _e('Port', WP_FFPC_PARAM); ?></label> + <label for="persistent"><?php _e('Persistent memcache connections', WP_FFPC_PARAM); ?></label> </dt> <dd> - <input type="number" name="port" id="port" value="<?php echo $this->options['port']; ?>" /> - <span class="description"><?php _e('Port for memcached server', WP_FFPC_PARAM); ?></span> - <span class="default"><?php _e('Default ', WP_FFPC_PARAM); ?>: <?php echo $this->defaults['port']; ?></span> + <input type="checkbox" name="persistent" id="persistent" value="1" <?php checked($this->options['persistent'],true); ?> /> + <span class="description"><?php _e('Make all memcache connections persistent. Be carefull with this setting, always test the outcome.', WP_FFPC_PARAM); ?></span> + <span class="default"><?php _e('Default ', WP_FFPC_PARAM); ?>: <?php echo $this->defaults['persistent']; ?></span> </dd> </dl> </fieldset>@@ -556,21 +569,16 @@ /* is deletion was unsuccessful, die, we have no rights to do that */
if ( @file_exists( $acache )) return false; - $string = '<?php'. "\n" . -'global '. WP_FFPC_CONFIG_VAR .' ;' . "\n"; - - foreach($this->options as $key => $val) { - if (is_string($val)) - $val = "'" . $val . "'"; + $string = '<?php'. "\n" . 'global '. WP_FFPC_CONFIG_VAR .";\n"; - $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"; file_put_contents($acache, $string); return true; } + /** * parameters array with default values;@@ -578,8 +586,7 @@ *
*/ 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 @@ 'nocache_single' => false,
'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,27 +682,30 @@ *
*/ 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 );@@ -696,6 +714,28 @@
if ( ! $firstrun ) $this->generate_config(); + } + + 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; } /**