all repos — wp-ffpc @ 0b3f7eb9aebba1f675d1c5a193333fc9284f9ee5

memcached nginx compatibility

git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@582237 b8457f37-d9ea-0310-8a92-e5e31aec5664
cadeyrn cadeyrn@b8457f37-d9ea-0310-8a92-e5e31aec5664
Mon, 06 Aug 2012 12:17:44 +0000
commit

0b3f7eb9aebba1f675d1c5a193333fc9284f9ee5

parent

9570df8e57f3f972d7c7a5d86c3009874be9e289

4 files changed, 107 insertions(+), 47 deletions(-)

jump to
M nginx-sample.confnginx-sample.conf

@@ -1,15 +1,27 @@

-location / { - try_files $uri $uri/ @memcached; -} +http { + ... + server { + ... -location @memcached { - default_type text/html; + location / { + try_files $uri $uri/ @memcached; + } - set $memcached_key DATAPREFIX$host$request_uri; - memcached_pass MEMCACHEDHOST:MEMCACHEDPORT; - error_page 404 = @rewrites; + location @memcached { + default_type text/html; + + set $memcached_key DATAPREFIX$host$request_uri; + memcached_pass MEMCACHEDHOST:MEMCACHEDPORT; + error_page 404 = @rewrites; + } + + location @rewrites { + rewrite ^(.*)$ /index.php?q=$1 last; + } + + ... + } } +... -location @rewrites { - rewrite ^(.*)$ /index.php?q=$1 last; -}+
M readme.txtreadme.txt

@@ -3,8 +3,8 @@ 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&currency_code=USD&bn=PP%2dDonationsBF%3acredit%2epng%3aNonHosted Tags: cache, APC, memcached, full page cache Requires at least: 3.0 -Tested up to: 3.3.1 -Stable tag: 0.3.2 +Tested up to: 3.4.1 +Stable tag: 0.4 Fast Full Page Cache, backend can be memcached or APC

@@ -30,9 +30,10 @@ (1) pingback hostname will always be generated from the accessed domain, otherwise speed would get highly compromised

(2) If used in WordPress Network, the configuration will only be available for network admins at the network admin panel, and will be system-wide and will be applied for every blog. -(3) nginx compatility means that if used with PHP Memcache (not Memcached!) extension, the created memcached entries can be read and served directly from nginx, making the cache insanely fast. -If used with APC or Memcached, this feature is not available (no APC module for nginx, compression incompatibility with Memcached), although, naturally, the cache modul is functional and working, but it will be done by PHP instead of nginx. -Short nginx example configuration is generated on the plugin settings page if Memcache is selected as cache type. +(3) nginx compatility means that if used with PHP Memcache or PHP Memcached extension, the created memcached entries can be read and served directly from nginx, making the cache insanely fast. +If used with APC, this feature is not available (no APC module for nginx), although, naturally, the cache modul is functional and working, but it will be done by PHP instead of nginx. +Short nginx example configuration is generated on the plugin settings page if Memcache or Memcached is selected as cache type. +NOTE: some features ( like pingback link in HTTP header ) will not be available with this solution! ( yet ) Some parts were based on [Hyper Cache](http://wordpress.org/extend/plugins/hyper-cache "Hyper Cache") plugin by Satollo (info@satollo.net).

@@ -44,18 +45,36 @@ 4. Fine tune the settings in `Settings` -> `wp-ffpc` menu in WordPress. For WordPress Network, please visit the Network Admin panel, the options will be available at WP-FFPC menu entry.

== Frequently Asked Questions == -= '%3C' character on home page load = += Known bugs = + +1. '%3C' character on home page load **Description**: When the page address is entered by hand, it gets redirected to `page.address/%3C`. - **Solution**: only occurs with memcached, the reason is yet unknown. The bug has emerged once for me as well, setting up everything and restarting the memcached server solved it. -= random-like characters instead of page = +2. random-like characters instead of page +***SOLVED, description below is outdated*** **Description**: when nginx is used with memcached, characters like `xœí}ksÛ8²èg»` shows up instead of the page. +**Solution**: this is the zlib compression of the page text. If PHP uses Memcached (with the 'd' at the ending), the compression cannot be turned off (it should, but it does not) and nginx is unable to read out the entries. +Please use only the Memcache extension. You also need to select it on the settings site, this is because some hosts may provide both PHP extensions. -**Solution**: this is the zlib compression of the page text. If PHP uses Memcached (with the 'd' at the ending), the compression cannot be turned off (it should, but it does not) and nginx is unable to read out the entries. -Please use only the Memcache extension. You also need to select it on the settings site, this is because some hosts may provide both PHP extensions, and if it's not going to be used with nginx, Memcached is better. + += How to install memcache PHP extension? = +You need to have PECL on your machine. If it's ready, type `pecl install memcache` as root. +Some additional libraries can also be needed, but that varies by linux distributions. + += How to use the plugin on Amazon Linux? = +You have to remove the default yum package, named `php-pecl-memcache` and install `Memcache` with PECL. == Changelog == + += 0.4 = +2012.08.06 +* tested against new WordPress versions +* added lines to "memcached" storage to be able to work with nginx as well +* added lines to "memcached" to use binary protocol ( tested with PHP Memcached version 2.0.1 ) + +KNOWN ISSUES +* "memcache" extension fails in binary mode; the reason is under investigation = 0.3.2 = 2012.02.27
M wp-ffpc-common.phpwp-ffpc-common.php

@@ -71,6 +71,8 @@ return false;

if ( $wp_ffpc_backend == NULL ) { $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_backend_status = array_key_exists( $wp_ffpc_config['host'] . ':' . $wp_ffpc_config['port'] , $wp_ffpc_backend->getStats() );

@@ -111,20 +113,16 @@ case 'apc':

if ( $post_only ) { apc_delete ( $meta ); - if ($wp_ffpc_config['syslog']) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . ' clearing key: "'. $meta . '"' . WP_FFPC_LOG_TYPE_MSG ); + wp_ffpc_log ( ' clearing key: "'. $meta . '"' ); apc_delete ( $data ); - if ($wp_ffpc_config['syslog']) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . ' clearing key: "'. $data . '"' . WP_FFPC_LOG_TYPE_MSG ); + wp_ffpc_log ( ' clearing key: "'. $data . '"' ); } else { apc_clear_cache('user'); - if ($wp_ffpc_config['syslog']) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . ' flushing user cache' . WP_FFPC_LOG_TYPE_MSG ); + wp_ffpc_log ( ' flushing user cache' ); apc_clear_cache('system'); - if ($wp_ffpc_config['syslog']) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . ' flushing system cache' . WP_FFPC_LOG_TYPE_MSG ); + wp_ffpc_log ( ' flushing system cache' ); } break;

@@ -135,17 +133,14 @@ global $wp_ffpc_backend;

if ( $post_only ) { $wp_ffpc_backend->delete( $meta ); - if ($wp_ffpc_config['syslog']) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . ' clearing key: "'. $meta . '"' . WP_FFPC_LOG_TYPE_MSG ); + wp_ffpc_log ( ' clearing key: "'. $meta . '"' ); $wp_ffpc_backend->delete( $data ); - if ($wp_ffpc_config['syslog']) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . ' clearing key: "'. $data . '"' . WP_FFPC_LOG_TYPE_MSG ); + wp_ffpc_log ( ' clearing key: "'. $data . '"' ); } else { $wp_ffpc_backend->flush(); - if ($wp_ffpc_config['syslog']) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . ' flushing cache' . WP_FFPC_LOG_TYPE_MSG ); + wp_ffpc_log ( ' flushing cache' ); } break;

@@ -167,6 +162,8 @@ function wp_ffpc_set ( &$key, &$data, $compress = false ) {

global $wp_ffpc_config; global $wp_ffpc_backend; + $exp = $wp_ffpc_config['user_logged_in'] ? $wp_ffpc_config['expire_member'] : $wp_ffpc_config['expire_visitor']; + /* syslog */ if ($wp_ffpc_config['syslog']) {

@@ -176,7 +173,7 @@ elseif ( @is_string( $data ))

$string = $data; $size = strlen($string); - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . ' set key: "'. $key . '", size: '. $size . ' byte(s)' . WP_FFPC_LOG_TYPE_MSG ); + wp_ffpc_log ( ' set key: "'. $key . '", size: '. $size . ' byte(s)' ); } switch ($wp_ffpc_config['cache_type'])

@@ -185,18 +182,18 @@ case 'apc':

/* use apc_store to overwrite data is existed */ if ( $compress ) $data = gzdeflate ( $data , 1 ); - return apc_store( $key , $data , $wp_ffpc_config['expire']); + return apc_store( $key , $data , $exp ); break; case 'memcache': if ( $wp_ffpc_backend != NULL ) /* false to disable compression, vital for nginx */ - $wp_ffpc_backend->set ( $key, $data , false, $wp_ffpc_config['expire'] ); + $wp_ffpc_backend->set ( $key, $data , false, $exp ); else return false; break; case 'memcached': if ( $wp_ffpc_backend != NULL ) - $wp_ffpc_backend->set ( $key, $data , $wp_ffpc_config['expire'] ); + $wp_ffpc_backend->set ( $key, $data , $exp ); else return false; break;

@@ -214,8 +211,7 @@ global $wp_ffpc_config;

global $wp_ffpc_backend; /* syslog */ - if ($wp_ffpc_config['syslog']) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM . ' get key: "'.$key . '"' . WP_FFPC_LOG_TYPE_MSG ); + wp_ffpc_log ( ' get key: "'.$key . '"' ); switch ($wp_ffpc_config['cache_type']) {

@@ -233,5 +229,20 @@ return false;

default: return false; } +} + + +/** + * handles log messages + * + * @param $string log messagr + */ +function wp_ffpc_log ( $string ) { + 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 ); + } ?>
M wp-ffpc.phpwp-ffpc.php

@@ -1,7 +1,7 @@

<?php /* Plugin Name: WP-FFPC -Version: 0.3.2 +Version: 0.4 Plugin URI: http://petermolnar.eu/wordpress/wp-ffpc Description: Fast Full Page Cache, backend can be memcached or APC Author: Peter Molnar

@@ -26,9 +26,27 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

*/ +/** + * checks for SSL connection +*/ +if ( ! function_exists ( 'replace_if_ssl' ) ) { + function replace_if_ssl ( $string ) { + if ( isset($_SERVER['HTTPS']) && ( ( strtolower($_SERVER['HTTPS']) == 'on' ) || ( $_SERVER['HTTPS'] == '1' ) ) ) + return str_replace ( 'http://' , 'https://' , $string ); + else + return $string; + } +} + /* fix */ -if ( ! defined( 'WP_PLUGIN_URL' ) ) - define( 'WP_PLUGIN_URL', get_option( 'siteurl' ) . '/wp-content/plugins' ); +if ( ! defined( 'WP_PLUGIN_URL_' ) ) +{ + if ( defined( 'WP_PLUGIN_URL' ) ) + define( 'WP_PLUGIN_URL_' , replace_if_ssl ( WP_PLUGIN_URL ) ); + else + define( 'WP_PLUGIN_URL_', replace_if_ssl ( get_option( 'siteurl' ) ) . '/wp-content/plugins' ); +} + if ( ! defined( 'WP_PLUGIN_DIR' ) ) define( 'WP_PLUGIN_DIR', ABSPATH . 'wp-content/plugins' );

@@ -36,7 +54,7 @@ /* constants */

define ( 'WP_FFPC_PARAM' , 'wp-ffpc' ); define ( 'WP_FFPC_OPTION_GROUP' , 'wp-ffpcparams' ); define ( 'WP_FFPC_OPTIONS_PAGE' , 'wp-ffpcoptions' ); -define ( 'WP_FFPC_URL' , WP_PLUGIN_URL . '/' . WP_FFPC_PARAM ); +define ( 'WP_FFPC_URL' , WP_PLUGIN_URL_ . '/' . WP_FFPC_PARAM ); define ( 'WP_FFPC_DIR' , WP_PLUGIN_DIR . '/' . WP_FFPC_PARAM ); define ( 'WP_FFPC_CONF_DIR' , WP_PLUGIN_DIR . '/' . WP_FFPC_PARAM .'/config' ); define ( 'WP_FFPC_ACACHE_MAIN_FILE' , ABSPATH . 'wp-content/advanced-cache.php' );

@@ -173,7 +191,7 @@ <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>

<?php endif; ?> <div class="wrap"> - <h2><?php _e( 'NMC settings', WP_FFPC_PARAM ) ; ?></h2> + <h2><?php _e( 'WP-FFPC settings', WP_FFPC_PARAM ) ; ?></h2> <form method="post" action="#"> <fieldset>

@@ -370,7 +388,7 @@

</dl> </fieldset> - <?php if ( $this->options['cache_type'] == 'memcache' ) : ?> + <?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>