From bbf98dda1fafa8c514821f4d36f04bc66de2c1c6 Mon Sep 17 00:00:00 2001 From: cadeyrn Date: Fri, 7 Dec 2012 16:57:18 +0000 Subject: [PATCH] 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 --- advanced-cache.php | 37 +++++++++++++---- nginx-sample.conf | 41 +++++++++++++++---- readme.txt | 11 +++++ wp-ffpc-common.php | 6 +-- wp-ffpc.php | 100 +++++++++++++++++++++++++++------------------ 5 files changed, 136 insertions(+), 59 deletions(-) diff --git a/advanced-cache.php b/advanced-cache.php index a3c0ed1..dd2a3dc 100644 --- a/advanced-cache.php +++ b/advanced-cache.php @@ -244,26 +244,49 @@ function wp_ffpc_callback($buffer) { 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 data */ - $data = $buffer; - wp_ffpc_set ( $wp_ffpc_data_key, $data , $compress ); + /* 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 ); + } + */ - /* vital for nginx version */ + /* set data */ + //$data = $buffer; + wp_ffpc_set ( $wp_ffpc_data_key, $buffer, $compress ); + + /* vital for nginx, make no problem at other places */ header("HTTP/1.1 200 OK"); + /* echoes HTML out */ return $buffer; } diff --git a/nginx-sample.conf b/nginx-sample.conf index a14867b..fb7f2c4 100644 --- a/nginx-sample.conf +++ b/nginx-sample.conf @@ -3,20 +3,43 @@ http { server { ... - location / { - try_files $uri $uri/ @memcached; - } - + # try to get result from memcached location @memcached { - default_type text/html; + default_type text/html; + set $memcached_key DATAPREFIX$scheme://$host$request_uri; + set $memcached_request 1; - set $memcached_key DATAPREFIX$scheme://$host$request_uri; - memcached_pass MEMCACHEDHOST:MEMCACHEDPORT; - error_page 404 = @rewrites; + # 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; + } + + if ( $memcached_request = 1) { + 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; } ... diff --git a/readme.txt b/readme.txt index e1aeb7c..9278221 100644 --- a/readme.txt +++ b/readme.txt @@ -67,6 +67,17 @@ You have to remove the default yum package, named `php-pecl-memcache` and instal == 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 diff --git a/wp-ffpc-common.php b/wp-ffpc-common.php index df24ea9..94fc216 100644 --- a/wp-ffpc-common.php +++ b/wp-ffpc-common.php @@ -60,7 +60,7 @@ function wp_ffpc_init( $wp_ffpc_config ) { $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 @@ function wp_ffpc_set ( &$key, &$data, $compress = false ) { { 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)' ); } diff --git a/wp-ffpc.php b/wp-ffpc.php index 649714c..ee44366 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -186,11 +186,38 @@ if (!class_exists('WPFFPC')) { * the admin panel itself */ ?> - -

WARNING: WP_CACHE is disabled, plugin will not work that way. Please add define( 'WP_CACHE', true ); into the beginning of wp-config.php

-
+ + +

+ + + +

+ + + + + options['cache_type'] == 'memcached' && $memcached_protocol == 'binary' ) : ?> +

+ + + 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; + ?> +

+ +

@@ -200,13 +227,13 @@ if (!class_exists('WPFFPC')) {
- +
- + : cache_type( $this->defaults['cache_type'] , true ) ; ?>
@@ -284,6 +311,15 @@ if (!class_exists('WPFFPC')) { : print_bool( $this->defaults['pingback_status']); ?> +
+ +
+
+ options['sync_protocols'],true); ?> /> + + : print_bool( $this->defaults['sync_protocols']); ?> +
+
@@ -347,24 +383,6 @@ if (!class_exists('WPFFPC')) {
- -

No PHP memcached extension was found. To use memcached, you need PHP Memcache or PHP Memcached extension.

- - - options['cache_type'] == 'memcached' || $this->options['cache_type'] == 'memcache' ) : ?> -
- - options); - - $server_status = ( empty($server_status) || $server_status == 0 ) ? 'down' : 'up & running' ; - echo $server_status; - ?> - -
- -
@@ -388,22 +406,6 @@ if (!class_exists('WPFFPC')) {
- options['cache_type'] == 'memcache' || $this->options['cache_type'] == 'memcached' ) : ?> - -
- - 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 ); - - ?> -
-
- - -
@@ -420,6 +422,23 @@ if (!class_exists('WPFFPC')) {
+ + options['cache_type'] == 'memcache' || $this->options['cache_type'] == 'memcached' ) : ?> + +
+ + 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 ); + + ?> +
+
+ + +

false, 'debug' => true, 'syslog' => false, - 'cache_type' => 'memcache', + 'cache_type' => 'memcached', 'cache_loggedin' => false, 'nocache_home' => false, 'nocache_feed' => false, @@ -547,6 +566,7 @@ if (!class_exists('WPFFPC')) { 'nocache_single' => false, 'nocache_page' => false, 'apc_compress' => false, + 'sync_protocols' => false, ); $this->defaults = $defaults;