diff --git a/readme.txt b/readme.txt index 8d081bc..13e78cf 100644 --- a/readme.txt +++ b/readme.txt @@ -113,30 +113,48 @@ Version numbering logic: = 1.7.0 = *2014-09-19* -* **dropped Xcache support**, the reasons behind this is the outstandingly terrible documentation of Xcache +What's new: + * added varying expiration time options +What's changed: + +* **dropped Xcache support**: the reasons behind this is the outstandingly terrible documentation of Xcache +* **dropped persistent memcache mode**: no one was using it and even if the were only caused trouble +* **removed '/wp-' hardcoded cache exception**; this is now the default in the regex exceptions field as ^/wp-; please add this manually in case you've already been using the regex field + +What's on it's way: + +* brace yourselves, redis support is coming = 1.6.4 = *2014-09-12* +What's fixed: + * downgraded log level from halting-level fatal to warning ( thank you PHP for the consistent naming... ) in case the selected extension is missing * leftover code parts cleanup = 1.6.3 = *2014-09-12* +What's fixed: + * there were still some alway-on log messages = 1.6.2 = *2014-09-05* +What's fixed: + * merge pulled from [plescheff](https://github.com/petermolnar/wp-ffpc/pull/25) * fixed bug of alway-on log messages ( warning was set to default where notice should have been ) = 1.6.1 = *2014-09-04* +What's fixed: + 1.6 release, correcting SVN madness with non-recursive copies. = 1.6.0 = diff --git a/wp-ffpc-acache.php b/wp-ffpc-acache.php index 5e6025e..fbc788a 100644 --- a/wp-ffpc-acache.php +++ b/wp-ffpc-acache.php @@ -30,10 +30,6 @@ $wp_ffpc_uri = $_SERVER['REQUEST_URI']; if ( isset($wp_ffpc_config['nocache_dyn']) && !empty($wp_ffpc_config['nocache_dyn']) && stripos($wp_ffpc_uri, '?') !== false ) return false; -/* no cache for pages starting with /wp- like WP admin */ -if (stripos($wp_ffpc_uri, '/wp-') !== false) - return false; - /* no cache for robots.txt */ if ( stripos($wp_ffpc_uri, 'robots.txt') ) return false; diff --git a/wp-ffpc-backend.php b/wp-ffpc-backend.php index 94c46d3..db44de2 100644 --- a/wp-ffpc-backend.php +++ b/wp-ffpc-backend.php @@ -672,11 +672,7 @@ class WP_FFPC_Backend { /* check is there's no backend connection yet */ if ( $this->connection === NULL ) { - /* persistent backend needs an identifier */ - if ( $this->options['persistent'] == '1' ) - $this->connection = new Memcached( $this->plugin_constant ); - else - $this->connection = new Memcached(); + $this->connection = new Memcached(); /* use binary and not compressed format, good for nginx and still fast */ $this->connection->setOption( Memcached::OPT_COMPRESSION , false ); @@ -714,7 +710,7 @@ class WP_FFPC_Backend { /* only add servers that does not exists already in connection pool */ if ( !@array_key_exists($server_id , $servers_alive ) ) { $this->connection->addServer( $server['host'], $server['port'] ); - $this->log ( sprintf( __translate__( '%s added, persistent mode: %s', $this->plugin_constant ), $server_id, $this->options['persistent'] ) ); + $this->log ( sprintf( __translate__( '%s added', $this->plugin_constant ), $server_id ) ); } } @@ -840,18 +836,13 @@ class WP_FFPC_Backend { /* adding servers */ foreach ( $this->options['servers'] as $server_id => $server ) { - if ( $this->options['persistent'] == '1' ) - $conn = 'pconnect'; - else - $conn = 'connect'; - /* in case of unix socket */ if ( $server['port'] === 0 ) - $this->status[$server_id] = $this->connection->$conn ( 'unix:/' . $server['host'] ); + $this->status[$server_id] = $this->connection->connect ( 'unix:/' . $server['host'] ); else - $this->status[$server_id] = $this->connection->$conn ( $server['host'] , $server['port'] ); + $this->status[$server_id] = $this->connection->connect ( $server['host'] , $server['port'] ); - $this->log ( sprintf( __translate__( '%s added, persistent mode: %s', $this->plugin_constant ), $server_id, $this->options['persistent'] ) ); + $this->log ( sprintf( __translate__( '%s added', $this->plugin_constant ), $server_id ) ); } /* backend is now alive */ @@ -869,7 +860,7 @@ class WP_FFPC_Backend { /* get servers statistic from connection */ foreach ( $this->options['servers'] as $server_id => $server ) { if ( $server['port'] === 0 ) - $this->status[$server_id] = $this->connection->getServerStatus( $server['host'] ); + $this->status[$server_id] = $this->connection->getServerStatus( $server['host'], 11211 ); else $this->status[$server_id] = $this->connection->getServerStatus( $server['host'], $server['port'] ); if ( $this->status[$server_id] == 0 ) @@ -934,6 +925,153 @@ class WP_FFPC_Backend { /*********************** END MEMCACHE FUNCTIONS ***********************/ + /*********************** REDIS FUNCTIONS ***********************/ + /** + * init memcache backend + */ + private function redis_init () { + if (!class_exists('Redis')) { + $this->log ( __translate__('PHP Redis extension missing', $this->plugin_constant ), LOG_WARNING ); + return false; + } + + /* check for existing server list, otherwise we cannot add backends */ + if ( empty ( $this->options['servers'] ) && ! $this->alive ) { + $this->log ( __translate__("servers list is empty, init failed", $this->plugin_constant ), LOG_WARNING ); + return false; + } + + /* check is there's no backend connection yet */ + if ( $this->connection === NULL ) + $this->connection = new Redis(); + + /* check if initialization was success or not */ + if ( $this->connection === NULL ) { + $this->log ( __translate__( 'error initializing Redis extension, exiting', $this->plugin_constant ) ); + return false; + } + + //$this->connection->setOption(Redis::OPT_PREFIX, $this->plugin_constant ); + + /* adding server * + foreach ( $this->options['servers'] as $server_id => $server ) { + /* in case of unix socket * + if ( $server['port'] === 0 ) { + try { + $this->status[$server_id] = $this->connection->connect ( $server['host'] ); + } catch ( RedisException $e ) { + $this->log ( sprintf( __translate__( 'adding %s to the Redis pool failed, error: %s', $this->plugin_constant ), $server['host'], $e ) ); + } + } + else { + try { + $this->status[$server_id] = $this->connection->connect ( $server['host'] , $server['port'] ); + } catch ( RedisException $e ) { + $this->log ( sprintf( __translate__( 'adding %s:%s to the Redis pool failed, error: %s', $this->plugin_constant ), $server['host'] , $server['port'], $e ) ); + } + } + + + $this->log ( sprintf( __translate__( 'server #%s added', $this->plugin_constant ), $server_id ) ); + }*/ + + /* adding server */ + $key = array_unshift ( array_keys ( $this->options['servers'] )); + $server = array_unshift( $this->options['servers'] ); + + try { + if ( $server['port'] === 0 ) + $this->status[$key] = $this->connection->connect ( $server['host'] ); + else + $this->status[$key] = $this->connection->connect ( $server['host'], $server['port'] ); + } catch ( RedisException $e ) { + $this->log ( sprintf( __translate__( 'adding %s to the Redis pool failed, error: %s', $this->plugin_constant ), $server['host'], $e ) ); + } + + $this->log ( sprintf( __translate__( 'server #%s added', $this->plugin_constant ), $server_id ) ); + + if ( !empty( $this->options['authpass'])) { + $auth = $this->connection->auth( $this->options['authpass'] ); + if ( $auth == false ) { + $this->log ( __translate__( 'Redis authentication failed, exiting', $this->plugin_constant ), LOG_WARNING ); + return false; + } + } + + /* backend is now alive */ + $this->alive = true; + $this->redis_status(); + } + + /** + * check current backend alive status for Memcached + * + */ + private function redis_status () { + /* server status will be calculated by getting server stats */ + $this->log ( __translate__("checking server statuses", $this->plugin_constant )); + + /* get servers statistic from connection */ + try { + $this->connection->ping(); + } catch ( RedisException $e ) { + $this->log ( sprintf( __translate__( 'Redis status check failed, error: %s', $this->plugin_constant ), $e ) ); + } + + $this->log ( sprintf( __translate__( 'Redis is up', $this->plugin_constant ), $server_id ) ); + } + + /** + * get function for Memcached backend + * + * @param string $key Key to get values for + * + */ + private function redis_get ( &$key ) { + return $this->connection->get($key); + } + + /** + * Set function for Memcached backend + * + * @param string $key Key to set with + * @param mixed $data Data to set + * + */ + private function redis_set ( &$key, &$data, &$expire ) { + $result = $this->connection->set ( $key, $data , Array('nx', 'ex' => $expire) ); + return $result; + } + + /** + * + * Flush memcached entries + */ + private function redis_flush ( ) { + return $this->connection->flushDB(); + } + + + /** + * Removes entry from Memcached or flushes Memcached storage + * + * @param mixed $keys String / array of string of keys to delete entries with + */ + private function redis_clear ( &$keys ) { + /* make an array if only one string is present, easier processing */ + if ( !is_array ( $keys ) ) + $keys = array ( $keys => true ); + + $kresults = $this->connection->delete( $keys ); + + foreach ( $kresults as $key => $value ) { + $this->log ( sprintf( __translate__( 'entry deleted: %s', $this->plugin_constant ), $value ) ); + } + } + + /*********************** END REDIS FUNCTIONS ***********************/ + + } endif; ?> diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index d15ed2d..ceaaba7 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -122,17 +122,17 @@ class WP_FFPC extends PluginAbstract { $this->select_cache_type = array ( 'apc' => __( 'APC' , $this->plugin_constant ), 'apcu' => __( 'APCu' , $this->plugin_constant ), - 'xcache' => __( 'XCache' , $this->plugin_constant ), 'memcache' => __( 'PHP Memcache' , $this->plugin_constant ), 'memcached' => __( 'PHP Memcached' , $this->plugin_constant ), + 'redis' => __( 'Redis (experimental, it will break!)' , $this->plugin_constant ), ); /* check for required functions / classes for the cache types */ $this->valid_cache_type = array ( 'apc' => function_exists( 'apc_cache_info' ) ? true : false, 'apcu' => function_exists( 'apcu_cache_info' ) ? true : false, - 'xcache' => function_exists( 'xcache_info' ) ? true : false, 'memcache' => class_exists ( 'Memcache') ? true : false, 'memcached' => class_exists ( 'Memcached') ? true : false, + 'redis' => class_exists( 'Redis' ) ? true : false, ); /* invalidation method possible values array */ @@ -446,7 +446,7 @@ class WP_FFPC extends PluginAbstract {
  • plugin_constant ); ?>
  • plugin_constant ); ?>
  • plugin_constant ); ?>
  • -
  • plugin_constant ); ?>
  • +
  • plugin_constant ); ?>
  • plugin_constant ); ?>
  • plugin_constant ); ?>
  • @@ -601,60 +601,61 @@ class WP_FFPC extends PluginAbstract {
    - -
    + plugin_constant); ?>
    - options['nocache_home'],true); ?> /> - plugin_constant); ?> - -
    + + + + + + + + + + + + + + + + + + + + + +
    + options['nocache_home'],true); ?> /> + plugin_constant); ?> + + options['nocache_feed'],true); ?> /> + plugin_constant); ?> + + options['nocache_archive'],true); ?> /> + plugin_constant); ?> + + options['nocache_page'],true); ?> /> + plugin_constant); ?> + + options['nocache_single'],true); ?> /> + plugin_constant); ?> + + options['nocache_dyn'],true); ?> /> + plugin_constant); ?> +
    - -
    -
    - options['nocache_feed'],true); ?> /> - plugin_constant); ?> -
    - -
    - -
    -
    - options['nocache_archive'],true); ?> /> - plugin_constant); ?> -
    - -
    - -
    -
    - options['nocache_single'],true); ?> /> - plugin_constant); ?> -
    - -
    - -
    -
    - options['nocache_page'],true); ?> /> - plugin_constant); ?> -
    - -
    - +
    - If you are caching with nginx, you should update your nginx configuration and reload nginx after changing this value.', $this->plugin_constant); ?> + If you are caching with nginx, you should update your nginx configuration and reload nginx after changing this value.', $this->plugin_constant); ?>
    - +
    - options['nocache_dyn'],true); ?> /> - plugin_constant); ?>
    @@ -671,8 +672,8 @@ class WP_FFPC extends PluginAbstract { -
    - plugin_constant); ?> +
    + plugin_constant); ?>
    @@ -680,18 +681,11 @@ class WP_FFPC extends PluginAbstract {
    - - 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 : .
    - in2.0.0b1 case using unix sockets with the Memcache driver: unix:// ', $this->plugin_constant); ?>
    -
    -
    - -
    -
    - options['persistent'],true); ?> /> - plugin_constant); ?> + - 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 : .
    - in2.0.0b1 case using unix sockets with the Memcache driver: unix:// ', $this->plugin_constant); ?>
    options['cache_type'], 'memcached') && extension_loaded ( 'memcached' ) && version_compare( phpversion( 'memcached' ) , '2.0.0', '>=' ) ) { ?> + if ( strstr ( $this->options['cache_type'], 'memcached') && extension_loaded ( 'memcached' ) && version_compare( phpversion( 'memcached' ) , '2.0.0', '>=' ) || ( $this->options['cache_type'] == 'redis' ) ) { ?> options['authuser'] ) || !empty( $this->options['authpass'] ) ) ) { ?>

    plugin_constant ) ?>

    @@ -872,6 +866,10 @@ class WP_FFPC extends PluginAbstract { * read hook; needs to be implemented */ public function plugin_extend_options_read( &$options ) { + /*if ( strstr( $this->options['nocache_url']), '^wp-' )wp_login_url() + $this->options['nocache_url'] = */ + + /* read the global options, network compatibility */ $this->global_config = get_site_option( $this->global_option ); diff --git a/wp-ffpc.php b/wp-ffpc.php index 39351cc..7d867b0 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -48,8 +48,7 @@ $wp_ffpc_defaults = array ( 'nocache_page' => false, 'nocache_cookies' => false, 'nocache_dyn' => true, - 'nocache_url' => '', - 'persistent' => false, + 'nocache_url' => '^/wp-', 'response_header' => false, 'generate_time' => false, 'precache_schedule' => 'null',