update on nginx sample; binary mode warning message git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@635450 b8457f37-d9ea-0310-8a92-e5e31aec5664
cadeyrn cadeyrn@b8457f37-d9ea-0310-8a92-e5e31aec5664
Fri, 07 Dec 2012 16:57:18 +0000
5 files changed,
134 insertions(+),
57 deletions(-)
M
advanced-cache.php
→
advanced-cache.php
@@ -244,26 +244,49 @@ /* try if post is available
if made with archieve, last listed post can make this go bad */ global $post; - if ( !empty($post) && ( $wp_ffpc_meta['type'] == 'single' || $wp_ffpc_meta['type'] == 'page' ) ) + if ( !empty($post) && ( $wp_ffpc_meta['type'] == 'single' || $wp_ffpc_meta['type'] == 'page' ) && !empty ( $post->post_modified_gmt ) ) { /* get last modification data */ - if (!empty ( $post->post_modified_gmt ) ) - $wp_ffpc_meta['lastmodified'] = strtotime ( $post->post_modified_gmt ); + $wp_ffpc_meta['lastmodified'] = strtotime ( $post->post_modified_gmt ); } /* APC compression */ $compress = ( ($wp_ffpc_config['cache_type'] == 'apc') && $wp_ffpc_config['apc_compress'] ) ? true : false; $wp_ffpc_meta['compressed'] = $compress; + /* sync all http and https requests if enabled */ + if ( !empty($wp_ffpc_config['sync_protocols']) ) + { + $sync_from = 'https://' . $_SERVER['SERVER_NAME']; + $sync_to = 'http://' . $_SERVER['SERVER_NAME']; + + if ( !empty( $_SERVER['HTTPS'] ) ) + { + $sync_from = 'http://' . $_SERVER['SERVER_NAME']; + $sync_to = 'https://' . $_SERVER['SERVER_NAME']; + } + $buffer = str_replace ( $sync_from, $sync_to, $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, $data , $compress ); + //$data = $buffer; + wp_ffpc_set ( $wp_ffpc_data_key, $buffer, $compress ); - /* vital for nginx version */ + /* vital for nginx, make no problem at other places */ header("HTTP/1.1 200 OK"); + /* echoes HTML out */ return $buffer; }
M
nginx-sample.conf
→
nginx-sample.conf
@@ -3,20 +3,43 @@ ...
server { ... - location / { - try_files $uri $uri/ @memcached; - } + # try to get result from memcached + location @memcached { + default_type text/html; + set $memcached_key DATAPREFIX$scheme://$host$request_uri; + set $memcached_request 1; + + # exceptions + # avoid cache serve of POST requests + if ($request_method = POST ) { + set $memcached_request 0; + } + # avoid cache serve of wp-admin-like pages, starting with "wp-" + if ( $uri ~ "/wp-" ) { + set $memcached_request 0; + } + # avoid cache for logged in users + if ($http_cookie ~* "comment_author_|wordpressuser_|wp-postpass_" ) { + set $memcached_request 0; + } - location @memcached { - default_type text/html; + if ( $memcached_request = 1) { + memcached_pass MEMCACHEDHOST:MEMCACHEDPORT; + error_page 404 = @rewrites; + } - set $memcached_key DATAPREFIX$scheme://$host$request_uri; - memcached_pass MEMCACHEDHOST:MEMCACHEDPORT; - error_page 404 = @rewrites; + if ( $memcached_request = 0) { + rewrite ^ /index.php$request_uri last; + } } + ## rewrite rules location @rewrites { - rewrite ^(.*)$ /index.php?q=$1 last; + rewrite ^ /index.php$request_uri last; + } + + location / { + try_files $uri $uri/ @memcached; } ...
M
readme.txt
→
readme.txt
@@ -67,6 +67,17 @@ You have to remove the default yum package, named `php-pecl-memcache` and install `Memcache` with PECL.
== Changelog == += 0.4.2 = +2012.11.30 + +* added sync protocoll option: replace all http->https or https->http depending on request protocol +* binary mode is working correctly with memcached extension +* + +KNOWN ISSUES + +There are major problems with the "memcache" driver, the source is yet unkown. The situation is that there's no response from the memcached server using this driver; please avoid using it! + = 0.4.1 = 2012.08.16
M
wp-ffpc-common.php
→
wp-ffpc-common.php
@@ -60,7 +60,7 @@ {
$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'] ); + $wp_ffpc_backend_status = $wp_ffpc_backend->getStats( ); break; /* in case of Memcached */@@ -170,10 +170,10 @@ if ($wp_ffpc_config['syslog'])
{ if ( @is_array( $data ) ) $string = serialize($data); - elseif ( @is_string( $data )) + else //if ( @is_string( $data ) || @ ) $string = $data; - $size = strlen($string); + $size = @strlen($string); wp_ffpc_log ( ' set key: "'. $key . '", size: '. $size . ' byte(s)' ); }
M
wp-ffpc.php
→
wp-ffpc.php
@@ -186,11 +186,38 @@ /**
* the admin panel itself */ ?> + + <div class="wrap"> + <?php if ( !WP_CACHE ) : ?> - <div class="updated settings-error"><p><strong>WARNING: WP_CACHE is disabled, plugin will not work that way. Please add define( 'WP_CACHE', true ); into the beginning of wp-config.php</strong></p></div> + <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; ?> + + <?php if ( !class_exists('Memcache') && !class_exists('Memcached') ) : ?> + <div class="updated settings-error"><p><strong><?php _e('No PHP memcached extension was found. To use memcached, you need PHP Memcache or PHP Memcached extension.', WP_FFPC_PARAM); ?></strong></p></div> + <?php endif; ?> + + <?php + $memcached_settings = ini_get_all( 'memcache' ); + $memcached_protocol = strtolower($memcached_settings['memcache.protocol']['local_value']); + ?> + + <?php if ( $this->options['cache_type'] == 'memcached' && $memcached_protocol == 'binary' ) : ?> + <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> + <?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; + ?> + </strong></p></div> <?php endif; ?> - <div class="wrap"> <h2><?php _e( 'WP-FFPC settings', WP_FFPC_PARAM ) ; ?></h2> <form method="post" action="#">@@ -200,13 +227,13 @@ <dl>
<div class="grid50"> <dt> - <label for="cache_type"><?php _e('Cache invalidation method', WP_FFPC_PARAM); ?></label> + <label for="cache_type"><?php _e('Select backend', WP_FFPC_PARAM); ?></label> </dt> <dd> <select name="cache_type" id="cache_type"> <?php $this->cache_type ( $this->options['cache_type'] ) ?> </select> - <span class="description"><?php _e('Select cache invalidation method.', WP_FFPC_PARAM); ?></span> + <span class="description"><?php _e('Select cache driver: ', WP_FFPC_PARAM); ?></span> <span class="default"><?php _e('Default ', WP_FFPC_PARAM); ?>: <?php $this->cache_type( $this->defaults['cache_type'] , true ) ; ?></span> </dd>@@ -284,6 +311,15 @@ <span class="description"><?php _e('Enable "X-Pingback" headers in cached pages; will always use accessed hostname as host!', WP_FFPC_PARAM); ?></span>
<span class="default"><?php _e('Default ', WP_FFPC_PARAM); ?>: <?php $this->print_bool( $this->defaults['pingback_status']); ?></span> </dd> + <dt> + <label for="sync_protocols"><?php _e("Enable sync protocolls", WP_FFPC_PARAM); ?></label> + </dt> + <dd> + <input type="checkbox" name="sync_protocols" id="sync_protocols" value="1" <?php checked($this->options['sync_protocols'],true); ?> /> + <span class="description"><?php _e('Enable to replace every protocol to the same as in the request for site\'s domain', WP_FFPC_PARAM); ?></span> + <span class="default"><?php _e('Default ', WP_FFPC_PARAM); ?>: <?php $this->print_bool( $this->defaults['sync_protocols']); ?></span> + </dd> + </div> <div class="grid50">@@ -347,24 +383,6 @@
<fieldset class="grid50"> <legend><?php _e('Settings for memcached backend', WP_FFPC_PARAM); ?></legend> - <?php if ( !class_exists('Memcache') && !class_exists('Memcached') ) : ?> - <h1 class="error">No PHP memcached extension was found. To use memcached, you need PHP Memcache or PHP Memcached extension.</h1> - <?php endif; ?> - - <?php if ( $this->options['cache_type'] == 'memcached' || $this->options['cache_type'] == 'memcache' ) : ?> - <div> - <strong> - <?php - _e( 'Backend status: ', 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; - ?> - </strong> - </div> - <?php endif; ?> - <dl> <dt>@@ -388,22 +406,6 @@
</dl> </fieldset> - <?php if ( $this->options['cache_type'] == 'memcache' || $this->options['cache_type'] == 'memcached' ) : ?> - - <fieldset class="grid50"> - <legend><?php _e('Sample config for nginx to utilize the data entries', WP_FFPC_PARAM); ?></legend> - <?php - $search = array( 'DATAPREFIX', 'MEMCACHEDHOST', 'MEMCACHEDPORT'); - $replace = array ( $this->options['prefix_data'], $this->options['host'], $this->options['port'] ); - $nginx = file_get_contents ( WP_FFPC_DIR .'/nginx-sample.conf' ); - $nginx = str_replace ( $search , $replace , $nginx ); - - ?> - <pre><?php echo $nginx; ?></pre> - </fieldset> - - <?php endif; ?> - <fieldset class="grid50"> <legend><?php _e('Settings for APC', WP_FFPC_PARAM); ?></legend> <dl>@@ -419,6 +421,23 @@ </dd>
</dl> </fieldset> + + + <?php if ( $this->options['cache_type'] == 'memcache' || $this->options['cache_type'] == 'memcached' ) : ?> + + <fieldset> + <legend><?php _e('Sample config for nginx to utilize the data entries', WP_FFPC_PARAM); ?></legend> + <?php + $search = array( 'DATAPREFIX', 'MEMCACHEDHOST', 'MEMCACHEDPORT'); + $replace = array ( $this->options['prefix_data'], $this->options['host'], $this->options['port'] ); + $nginx = file_get_contents ( WP_FFPC_DIR .'/nginx-sample.conf' ); + $nginx = str_replace ( $search , $replace , $nginx ); + + ?> + <pre><?php echo $nginx; ?></pre> + </fieldset> + + <?php endif; ?> <p class="clearcolumns"><input class="button-primary" type="submit" name="<?php echo WP_FFPC_PARAM; ?>-save" id="<?php echo WP_FFPC_PARAM; ?>-save" value="Save Changes" /></p> </form>@@ -539,7 +558,7 @@ 'charset' => 'utf-8',
'pingback_status'=> false, 'debug' => true, 'syslog' => false, - 'cache_type' => 'memcache', + 'cache_type' => 'memcached', 'cache_loggedin' => false, 'nocache_home' => false, 'nocache_feed' => false,@@ -547,6 +566,7 @@ 'nocache_archive' => false,
'nocache_single' => false, 'nocache_page' => false, 'apc_compress' => false, + 'sync_protocols' => false, ); $this->defaults = $defaults;