pre-1.7.0

This commit is contained in:
Peter Molnar 2014-09-19 12:18:18 +01:00
parent 0356107ea7
commit 8d14b21ad8
5 changed files with 228 additions and 79 deletions

View file

@ -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 =

View file

@ -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;

View file

@ -672,10 +672,6 @@ 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();
/* use binary and not compressed format, good for nginx and still fast */
@ -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; ?>

View file

@ -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 {
<li><a href="#<?php echo $this->plugin_constant ?>-type" class="wp-switch-editor"><?php _e( 'Cache type', $this->plugin_constant ); ?></a></li>
<li><a href="#<?php echo $this->plugin_constant ?>-debug" class="wp-switch-editor"><?php _e( 'Debug & in-depth', $this->plugin_constant ); ?></a></li>
<li><a href="#<?php echo $this->plugin_constant ?>-exceptions" class="wp-switch-editor"><?php _e( 'Cache exceptions', $this->plugin_constant ); ?></a></li>
<li><a href="#<?php echo $this->plugin_constant ?>-memcached" class="wp-switch-editor"><?php _e( 'Memcache(d)', $this->plugin_constant ); ?></a></li>
<li><a href="#<?php echo $this->plugin_constant ?>-servers" class="wp-switch-editor"><?php _e( 'Backend settings', $this->plugin_constant ); ?></a></li>
<li><a href="#<?php echo $this->plugin_constant ?>-nginx" class="wp-switch-editor"><?php _e( 'nginx', $this->plugin_constant ); ?></a></li>
<li><a href="#<?php echo $this->plugin_constant ?>-precache" class="wp-switch-editor"><?php _e( 'Precache & precache log', $this->plugin_constant ); ?></a></li>
</ul>
@ -601,60 +601,61 @@ class WP_FFPC extends PluginAbstract {
</dd>
<dt>
<label for="nocache_home"><?php _e("Don't cache home", $this->plugin_constant); ?></label>
</dt>
<?php _e("Excludes", $this->plugin_constant); ?></label>
<dd>
<table style="width:100%">
<thead>
<tr>
<th style="width:16%; text-align:left"><label for="nocache_home"><?php _e("Exclude home", $this->plugin_constant); ?></label></th>
<th style="width:16%; text-align:left"><label for="nocache_feed"><?php _e("Exclude feeds", $this->plugin_constant); ?></label></th>
<th style="width:16%; text-align:left"><label for="nocache_archive"><?php _e("Exclude archives", $this->plugin_constant); ?></label></th>
<th style="width:16%; text-align:left"><label for="nocache_page"><?php _e("Exclude pages", $this->plugin_constant); ?></label></th>
<th style="width:16%; text-align:left"><label for="nocache_single"><?php _e("Exclude singulars", $this->plugin_constant); ?></label></th>
<th style="width:17%; text-align:left"><label for="nocache_dyn"><?php _e("Dynamic requests", $this->plugin_constant); ?></label></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="checkbox" name="nocache_home" id="nocache_home" value="1" <?php checked($this->options['nocache_home'],true); ?> />
<span class="description"><?php _e('Exclude home page from caching', $this->plugin_constant); ?></span>
</dd>
<dt>
<label for="nocache_feed"><?php _e("Don't cache feeds", $this->plugin_constant); ?></label>
</dt>
<dd>
<span class="description"><?php _e('Never cache home.', $this->plugin_constant); ?>
</td>
<td>
<input type="checkbox" name="nocache_feed" id="nocache_feed" value="1" <?php checked($this->options['nocache_feed'],true); ?> />
<span class="description"><?php _e('Exclude feeds from caching.', $this->plugin_constant); ?></span>
</dd>
<dt>
<label for="nocache_archive"><?php _e("Don't cache archives", $this->plugin_constant); ?></label>
</dt>
<dd>
<span class="description"><?php _e('Never cache feeds.', $this->plugin_constant); ?>
</td>
<td>
<input type="checkbox" name="nocache_archive" id="nocache_archive" value="1" <?php checked($this->options['nocache_archive'],true); ?> />
<span class="description"><?php _e('Exclude archives from caching.', $this->plugin_constant); ?></span>
</dd>
<dt>
<label for="nocache_single"><?php _e("Don't cache posts (and single-type entries)", $this->plugin_constant); ?></label>
</dt>
<dd>
<input type="checkbox" name="nocache_single" id="nocache_single" value="1" <?php checked($this->options['nocache_single'],true); ?> />
<span class="description"><?php _e('Exclude singles from caching.', $this->plugin_constant); ?></span>
</dd>
<dt>
<label for="nocache_page"><?php _e("Don't cache pages", $this->plugin_constant); ?></label>
</dt>
<dd>
<span class="description"><?php _e('Never cache archives.', $this->plugin_constant); ?>
</td>
<td>
<input type="checkbox" name="nocache_page" id="nocache_page" value="1" <?php checked($this->options['nocache_page'],true); ?> />
<span class="description"><?php _e('Exclude pages from caching.', $this->plugin_constant); ?></span>
</dd>
<span class="description"><?php _e('Never cache pages.', $this->plugin_constant); ?>
</td>
<td>
<input type="checkbox" name="nocache_single" id="nocache_single" value="1" <?php checked($this->options['nocache_single'],true); ?> />
<span class="description"><?php _e('Never cache singulars.', $this->plugin_constant); ?>
</td>
<td>
<input type="checkbox" name="nocache_dyn" id="nocache_dyn" value="1" <?php checked($this->options['nocache_dyn'],true); ?> />
<span class="description"><?php _e('Exclude every URL with "?" in it.', $this->plugin_constant); ?></span>
</td>
</tr>
</tbody>
</table>
<dt>
<label for="nocache_cookies"><?php _e("Don't cache cookies", $this->plugin_constant); ?></label>
<label for="nocache_cookies"><?php _e("Exclude based on cookies", $this->plugin_constant); ?></label>
</dt>
<dd>
<input type="text" name="nocache_cookies" id="nocache_cookies" value="<?php if(isset( $this->options['nocache_cookies'] ) ) echo $this->options['nocache_cookies']; ?>" />
<span class="description"><?php _e('Exclude cookies names starting with this from caching. Separate multiple cookies names with commas.<br />If you are caching with nginx, you should update your nginx configuration and reload nginx after changing this value.', $this->plugin_constant); ?></span>
<span class="description"><?php _e('Exclude content based on cookies names starting with this from caching. Separate multiple cookies names with commas.<br />If you are caching with nginx, you should update your nginx configuration and reload nginx after changing this value.', $this->plugin_constant); ?></span>
</dd>
<dt>
<label for="nocache_dyn"><?php _e("Don't cache dynamic requests", $this->plugin_constant); ?></label>
</dt>
<dd>
<input type="checkbox" name="nocache_dyn" id="nocache_dyn" value="1" <?php checked($this->options['nocache_dyn'],true); ?> />
<span class="description"><?php _e('Exclude every URL with "?" in it.', $this->plugin_constant); ?></span>
</dd>
<dt>
@ -671,8 +672,8 @@ class WP_FFPC extends PluginAbstract {
</dl>
</fieldset>
<fieldset id="<?php echo $this->plugin_constant ?>-memcached">
<legend><?php _e('Settings for memcached backend', $this->plugin_constant); ?></legend>
<fieldset id="<?php echo $this->plugin_constant ?>-servers">
<legend><?php _e('Backend server settings', $this->plugin_constant); ?></legend>
<dl>
<dt>
<label for="hosts"><?php _e('Hosts', $this->plugin_constant); ?></label>
@ -680,18 +681,11 @@ class WP_FFPC extends PluginAbstract {
<dd>
<input type="text" name="hosts" id="hosts" value="<?php echo $this->options['hosts']; ?>" />
<span class="description">
<?php _e('List of memcached backends, with the following syntax: <br />- 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 : .<br />- in2.0.0b1 case using unix sockets with the Memcache driver: unix:// ', $this->plugin_constant); ?></span>
</dd>
<dt>
<label for="persistent"><?php _e('Persistent memcache connections', $this->plugin_constant); ?></label>
</dt>
<dd>
<input type="checkbox" name="persistent" id="persistent" value="1" <?php checked($this->options['persistent'],true); ?> />
<span class="description"><?php _e('Make all memcache(d) connections persistent. Be careful with this setting, always test the outcome.', $this->plugin_constant); ?></span>
<?php _e('List of backends, with the following syntax: <br />- 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 : .<br />- in2.0.0b1 case using unix sockets with the Memcache driver: unix:// ', $this->plugin_constant); ?></span>
</dd>
<?php
if ( strstr ( $this->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' ) ) { ?>
<?php
if ( ! ini_get('memcached.use_sasl') && ( !empty( $this->options['authuser'] ) || !empty( $this->options['authpass'] ) ) ) { ?>
<div class="error"><p><strong><?php _e( 'WARNING: you\'ve entered username and/or password for memcached authentication ( or your browser\'s autocomplete did ) which will not work unless you enable memcached sasl in the PHP settings: add `memcached.use_sasl=1` to php.ini' , $this->plugin_constant ) ?></strong></p></div>
@ -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 );

View file

@ -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',