diff --git a/readme.txt b/readme.txt index 375b1e1..39bf4af 100644 --- a/readme.txt +++ b/readme.txt @@ -1,49 +1,35 @@ === WP-FFPC === Contributors: cadeyrn Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC -Tags: cache, APC, memcache, memcached, page cache, full page cache, nginx +Tags: cache, memcached, full page cache, NGiNX, memcache, page cache Requires at least: 3.0 Tested up to: 3.5.1 -Stable tag: 0.6.1 +Stable tag: 1.0 +License: GPLv3 +License URI: http://www.gnu.org/licenses/gpl-3.0.html -Store WordPress pages in memcached and serve them with nginx - unbeatable speed! +Cache WordPress to memcached and serve them with NGiNX - unbeatable speed! == Description == -WP-FFPC is a full page cache plugin for WordPress. Supports memcached server or APC as backend and both widely available PHP memcached modules, Memcache and Memcached as well. - -= Support & Info = -I provide support for the plugin as best as I can, but it comes without guarantee. -Please post feature requests to [WP-FFPC feature request topic](http://wordpress.org/support/topic/feature-requests-14 "WP-FFPC feature request topic"). - -= Notice for versions before 0.6.1 = -**from version 0.6.1 a lot of things have changed, including true multisite support ( possible per site different settings in a network ), rewritten memcached backend, etc. Please delete the previous settings by using the "delete options" button on the bottom right of the settings page after upgrading from previous versions.** +WP-FFPC ( WordPress Fast Full Page Cache ) is a cache plugin for [WordPress](http://wordpress.org/ "WordPress"). +Supports PHP Memcached, PHP Memcache and APC as storage engines. = Features: = -* exclude possibilities: of home, feeds, archieves, pages, singles -* possibility to enable caching for logged-in users -* APC or memcached server storage +* [NGiNX](http://NGiNX.org "NGiNX") compatibility +* full Wordpress Network support +* cache exclude possibilities ( home, feeds, archieves, pages, singles ) +* (optional) cache for logged-in users * 404 caching -* redirects caching -* Last Modified HTTP header compatibility with 304 responses +* canonical redirects caching +* Last Modified HTTP header support ( for 304 responses ) * shortlink HTTP header preservation -* pingback HTTP header preservation(1) -* fallback to no caching if any error or problem occurs -* syslog & debug settings for troubleshooting -* supports multiple memcached backends -* Wordpress Network compatible (2) -* nginx compatible(3) +* pingback HTTP header preservation +* (optional) talkative log for troubleshooting +* multiple memcached upstream support -(1) pingback hostname will always be generated from the accessed domain, otherwise speed would get highly compromised +Many thanks for supporters, testers & bug reporters: [Eric Gilette](http://www.ericgillette.com/ "Eric Gilette"); [doconeill](http://wordpress.org/support/profile/doconeill "doconeill"); [Mark Costlow](mailto:cheeks@swcp.com "Mark Costlow"). -(2) Plugin is capable of either Network wide or per site settings, meaning if not network-wide enabled, settings could vary from site to site, plugin could be turned off and on without interfering other sites. -**Only for subdomain ( or different domain) setup**, subdirectory setup is not yet supported! - -(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. -If used with APC, this feature is not available (no APC module for nginx). -Short nginx example configuration is generated on the plugin settings page, under `nginx` tab according to the settings of the plugin. -NOTE: some features ( most of additional HTTP headers for example, like pingback, shortlink, etc. ) will not be available with this solution! ( yet ) - -Parts are based on [Hyper Cache](http://wordpress.org/extend/plugins/hyper-cache "Hyper Cache") plugin by Satollo (info@satollo.net). +Thanks for [Hyper Cache](http://wordpress.org/extend/plugins/hyper-cache "Hyper Cache") for beeing inspirational. == Installation == @@ -55,13 +41,32 @@ Parts are based on [Hyper Cache](http://wordpress.org/extend/plugins/hyper-cache == Frequently Asked Questions == -= How to install memcache PHP extension? = -On most of the distributions, php5-memcached or php5-memcache is available as package. -You can use PECL alternatively: `pecl install memcached`. -It's recommended to use Memcached instead of Memcache. - = How to use the plugin on Amazon Linux? = -You have to remove the default yum package, named `php-pecl-memcache` and install `Memcache` or `Memcached` through PECL. +You have to remove the default yum package, named `php-pecl-memcache` and install `Memcached` through PECL. + += Information: network wide settings always overwrite site settings = +Since the plugin can be used as per-site configured in a network, if the plugin get network active later, the network settings will always overwrite the per site configuration. + += Information: Log levels = +Log levels ( if logging enabled ) includes info, warning and error level messages; error level most usually means PHP configuration error or missing plugin configuration. + += Information: Using it with NGiNX = +If the storage engine is either PHP Memcache or PHP Memcached extension, the created entries can be read and served directly from NGiNX ( if it has memcache or memc extension ) +A short configuration example is generated on the plugin settings page, under `NGiNX` tab according to the saved settings. +**NOTE** Some features ( most of additional HTTP headers for example, like pingback, shortlink, etc. ) will not be available with this solution. + += Information: Support & Info = +I provide support for the plugin as best as I can, but it comes without guarantee. +Please post feature requests to [WP-FFPC feature request topic](http://wordpress.org/support/topic/feature-requests-14 "WP-FFPC feature request topic"). + += PLugin requirements = +* WordPress >= 3.0 + +and **at least one** of the following for storage backend: +* PHP APC +* PHP Memcached > 0.1.0 +* PHP Memcache > 2.1.0 + == Screenshots == @@ -70,10 +75,32 @@ You have to remove the default yum package, named `php-pecl-memcache` and instal 3. cache exceptions 4. apc settings 5. memcached servers settings -6. nginx example +6. NGiNX example == Changelog == += 1.0 = +*in RC state* + +* Software licence change from GPLv2 to GPLv3 +* backend code completely replaced ( object-based backend, improved readability & better structure, lot less global vars, etc. ) +* revisited multisite support ( solved overwriting-problems ) +* preparations for localization support ( all strings are now go through WordPress translate except for advanced-cache logging, since there's no WordPress available at that point ) +* more and more detailed log & error messages +* retouched Memcache initialization ( faster connect ) + +**Bugfixes** +* reported bug of faulty expiration times fixed +* eliminated warning message for memcache when no memcache extension is present +* fixed multisite settings overwriting issue + +**Dropped functions** +* APC entry compression support + +**Planned features for next major release** +* support for Redis backend +* optional NGiNX header preservation for shortlink, pingback and last-modified headers + = 0.6.1 = *2013.03.08* @@ -135,7 +162,7 @@ There are major problems with the "memcache" driver, the source is yet unkown. T *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" 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** @@ -156,7 +183,7 @@ There are major problems with the "memcache" driver, the source is yet unkown. T = 0.2.3 = *2012.02.21* -* nginx-sample.conf file added, nginx config is created from here +* NGiNX-sample.conf file added, NGiNX config is created from here = 0.2.2 = *2012.02.21* diff --git a/wp-ffpc.php b/wp-ffpc.php index 10959e4..bcf992c 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -1,930 +1,54 @@ -settingslink = 'options-general.php?page=' . WP_FFPC_OPTIONS_PAGE; - - /* check if plugin is network-activated */ - $this->check_for_network(); - - /* register options */ - $this->get_options(); - - /* check is backend is available */ - $alive = wp_ffpc_init( $this->options ); - - /* don't register hooks if backend is dead */ - if (!$alive) - { - /* init inactivation hooks */ - add_action('switch_theme', array( $this , 'invalidate'), 0); - add_action('edit_post', array( $this , 'invalidate'), 0); - add_action('publish_post', array( $this , 'invalidate'), 0); - add_action('delete_post', array( $this , 'invalidate'), 0); - - /* Capture and register if a redirect is sent back from WP, so the cache - can cache (or ignore) it. Redirects were source of problems for blogs - with more than one host name (eg. domain.com and www.domain.com) comined - with the use of Hyper Cache.*/ - add_filter('redirect_canonical', array( $this , 'redirect_canonical') , 10, 2); - } - - $plugin = plugin_basename( __FILE__ ); - if ( $this->network ) - add_filter( "network_admin_plugin_action_links_$plugin", array( $this, 'settings_link' ) ); - else - add_filter( "plugin_action_links_$plugin", array( $this, 'settings_link' ) ); - - /* add admin styling */ - if( is_admin() ) - { - wp_enqueue_script ( "jquery-ui-tabs" ); - wp_enqueue_style( WP_FFPC_PARAM . '.admin.css' , WP_FFPC_URL . '/' . WP_FFPC_PARAM .'.admin.css', false, '0.1'); - } - - /* on activation */ - register_activation_hook(__FILE__ , array( $this , 'activate') ); - - /* on deactivation */ - register_deactivation_hook(__FILE__ , array( $this , 'deactivate') ); - - /* on uninstall */ - register_uninstall_hook(__FILE__ , array( $this , 'uninstall') ); - - /* init plugin in the admin section */ - /* if multisite, admin page will be on network admin section */ - if ( $this->network ) - add_action('network_admin_menu', array( $this , 'admin_init') ); - /* not network, will be in simple admin menu */ - else - add_action('admin_menu', array( $this , 'admin_init') ); - - if ( $this->all_options['version'] < WP_FFPC_VERSION ) { - $this->save_settings (); - if ( @file_exists( WP_FFPC_ACACHE_MAIN_FILE )) { - $this->generate_config(); - } - } - } - - /** - * activation hook: save default settings in order to eliminate bugs. - * - */ - function activate ( ) { - - /* register options for first time */ - add_site_option( WP_FFPC_PARAM, $this->options , '' , 'yes'); - - $this->save_settings( true ); - } - - /** - * init function for admin section - * - */ - function admin_init () { - /* save parameter updates, if there are any */ - if ( isset($_POST[WP_FFPC_PARAM . '-save']) ) - { - $this->save_settings (); - $this->status = 1; - - header( "Location: ". $this->settingslink ."&saved=true" ); - } - - /* save parameter updates, if there are any */ - if ( isset($_POST[WP_FFPC_PARAM . '-delete']) ) - { - $this->delete_options(); - $this->status = 2; - header( "Location: ". $this->settingslink ."&deleted=true" ); - } - - if ( $this->network ) - $optionspage = 'settings.php'; - else - $optionspage = 'options-general.php'; - - /* we use settings menu, no need for highest level menu */ - add_submenu_page( $optionspage, 'Edit WP-FFPC options', __('WP-FFPC', WP_FFPC_PARAM ), 10, WP_FFPC_OPTIONS_PAGE , array ( $this , 'admin_panel' ) ); - } - - /** - * settings panel at admin section - * - */ - function admin_panel ( ) { - - /** - * security - */ - if( ! function_exists( 'current_user_can' ) || ! current_user_can( 'manage_options' ) ){ - die( ); - } - - /** - * if options were saved - */ - if ($_GET['saved']=='true' || $this->status == 1) : ?> -

Settings saved.

- status == 2) : ?> -

Plugin options deleted.

- - - - -
- -

This plugin helped your business? Buy me a coffee for having it, please :)

- - -

- - - -

- - - options['cache_type'] == 'memcached' && !class_exists('Memcached') ) : ?> -

- - - options['cache_type'] == 'memcache' && !class_exists('Memcache') ) : ?> -

- - - - - options['cache_type'] == 'memcache' && $memcached_protocol == 'binary' ) : ?> -

- - - options['cache_type'] == 'memcached' || $this->options['cache_type'] == 'memcache' ) : ?> -
-

- options['cache_type']; - ?> -

-

- Backend status:
', WP_FFPC_PARAM ); - $init = wp_ffpc_init( $this->options ); - /* we need to go through all servers */ - foreach ( $this->options['servers'] as $server_string => $server ) { - echo $server['host'] . ":" . $server['port'] ." => "; - if ( is_array($init) && $init[$server_string] === false ) - _e ( 'down
', WP_FFPC_PARAM ); - elseif ( is_array($init) && $init[$server_string] === true ) - _e ( 'up & running
', WP_FFPC_PARAM ); - else - _e ( 'unknown, please try re-saving settings!
', WP_FFPC_PARAM ); - } - ?> -

-
- - -

-
- - - -
- -
-
- -
-
- - - : cache_type( $this->defaults['cache_type'] , true ) ; ?> -
- -
- -
-
- - - : defaults['expire']; ?> -
- -
- -
-
- - - : defaults['charset']; ?> -
- -
- -
-
- - WARNING! When selection "all", the cache will be fully flushed, including elements that were set by other applications.

', WP_FFPC_PARAM); ?>
- : invalidation_method( $this->defaults['invalidation_method'] , true ) ; ?> -
- -
- -
-
- - - : defaults['prefix_data']; ?> -
- -
- -
-
- - - : defaults['prefix_meta']; ?> -
-
-
- -
- -
-
- -
-
- options['debug'],true); ?> /> - - : print_bool( $this->defaults['debug']); ?> -
- -
- -
-
- options['syslog'],true); ?> /> - - : print_bool( $this->defaults['syslog']); ?> -
- -
- -
-
- options['pingback_status'],true); ?> /> - - : print_bool( $this->defaults['pingback_status']); ?> -
- -
- -
-
- options['sync_protocols'],true); ?> /> - - : print_bool( $this->defaults['sync_protocols']); ?> -
-
-
- -
- -
-
- -
-
- options['cache_loggedin'],true); ?> /> - - : print_bool( $this->defaults['cache_loggedin']); ?> -
- -
- -
-
- options['nocache_home'],true); ?> /> - - : print_bool( $this->defaults['nocache_home']); ?> -
- -
- -
-
- options['nocache_feed'],true); ?> /> - - : print_bool( $this->defaults['nocache_feed']); ?> -
- -
- -
-
- options['nocache_archive'],true); ?> /> - - : print_bool( $this->defaults['nocache_archive']); ?> -
- -
- -
-
- options['nocache_single'],true); ?> /> - - : print_bool( $this->defaults['nocache_single']); ?> -
- -
- -
-
- options['nocache_page'],true); ?> /> - - : print_bool( $this->defaults['nocache_page']); ?> -
-
-
- -
- -
- -
- -
-
- options['apc_compress'],true); ?> /> - - : print_bool( $this->defaults['apc_compress']); ?> -
- -
-
- -
- -
-
- -
-
- - - : defaults['host']; ?> -
-
- -
-
- options['persistent'],true); ?> /> - - : defaults['persistent']; ?> -
-
-
- -
- - 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 ); - - foreach ( array_keys( $this->options['servers'] ) as $server ) { - $nginx_servers .= " server ". $server .";\n"; - } - - $nginx = str_replace ( 'MEMCACHED_SERVERS' , $nginx_servers , $nginx ); - - ?> -
-
- -

- - -

-
- input field with $current set as active - * - */ - function cache_type ( $current , $returntext = false ) { - - $e = array ( - 'apc' => 'use APC as store', - 'memcache' => 'use memcached server with Memcache extension', - 'memcached' => 'use memcached server with Memcached extension', - ); - - $this->print_select_options ( $e , $current , $returntext ); - - } - - /** - * see if we are using network-wide setup or not - * - */ - function check_for_network( ) { - - $this->options_key = $_SERVER['HTTP_HOST']; - - if ( is_plugin_active_for_network ( WP_FFPC_PLUGIN ) ) - { - /* set active for network */ - $this->network = true; - /* replace settings link */ - $this->settingslink = str_replace( 'options-general.php' , 'settings.php' , $this->settingslink ); - /* set options key */ - $this->options_key = 'network'; - } - - } - - /** - * deactivation hook: clear advanced-cache config file - * - */ - function deactivate ( ) { - //if (@file_exists (WP_FFPC_ACACHE_MAIN_FILE)) - // @unlink (WP_FFPC_ACACHE_MAIN_FILE); - $this->save_settings( false, true ); - //$this->generate_config ( true ); - } - - /** - * delete options from database - * - */ - function delete_options () { - delete_site_option( WP_FFPC_PARAM ); - wp_ffpc_log ( "plugin options deleted "); - } - - /** - * invalidate cache - * - * @param $post_id - * id of post to be removed from cache entries - */ - function invalidate ( $post_id ) { - wp_ffpc_clear ( $post_id ); - } - - /** - * generates invalidation method select box - * - * @param $current - * the active or required size's identifier - * - * @param $returntext - * boolean: is true, the description will be returned of $current size - * - * @return - * prints either description of $current - * or option list for a input field with $current set as active - * - */ - function print_select_options ( $sizes, $current, $returntext=false ) { - - if ( $returntext ) - { - _e( $sizes[ $current ] , WP_FFPC_PARAM); - return; - } - - foreach ($sizes as $ext=>$name) - { - ?> - - all_options[ $this->options_key ] ); - else - $this->update_settings( $firstrun ); - - $this->all_options['version'] = WP_FFPC_VERSION; - - /* save options */ - update_site_option( WP_FFPC_PARAM , $this->all_options ); - - /* invalidate cache, this is neccessary */ - $this->invalidate('system_flush'); - - /* if it's not for the first run, generate the config file */ - if ( ! $firstrun ) - $this->generate_config( ); - - } - - /** - * - * - */ - function settings_link ( $links ) { - $settings_link = '' . __( 'Settings', WP_FFPC_PARAM ) . ''; - array_unshift( $links, $settings_link ); - return $links; - } - - /** - * splits config parameter "hosts" into an array of server string, host and port - * to be used in later config - * - */ - function split_hosts ( ) { - - $servers = explode( WP_FFPC_SERVER_LIST_SEPARATOR , $this->options['hosts']); - $good_servers = array(); - - foreach ( $servers as $server_num => $server_string ) { - $separator = strpos( $server_string , WP_FFPC_SERVER_SEPARATOR ); - $host = substr( $server_string, 0, $separator ); - $port = substr( $server_string, $separator + 1 ); - - if ( !empty ( $host ) && !empty($port) && is_numeric($port) ) { - $good_servers[$server_string] = array ( - 'host' => $host, - 'port' => $port - ); - } - } - - if ( !empty ( $good_servers )) - $this->options['servers'] = $good_servers; - } - - /** - * clean up at uninstall - * - */ - function uninstall ( ) { - delete_site_option( WP_FFPC_PARAM ); - wp_ffpc_log ( "plugin uninstalled "); - } - - - function update_settings ( $firstrun = false ) { - $options = $this->defaults; - - /* only try to update defaults if it's not first run and $_POST is not empty */ - if ( !$firstrun && !empty ( $_POST ) ) - { - foreach ( $options as $key => $default ) - { - /* $_POST element is available */ - if (!empty($_POST[$key])) - { - $update = $_POST[$key]; - /* get rid of slashed */ - if ( strlen( $update ) !=0 &&!is_numeric($update) ) - $update = stripslashes($update); - - $options[$key] = $update; - } - /* empty $_POST element: when HTML form posted, empty checkboxes a 0 values will not be - part of the $_POST array, thus we need to check if this is the situation by - checking the types of the elements, since a missing value could mean update from 1 to 0 - */ - elseif ( empty( $_POST[$key] ) && ( is_bool ( $default ) || is_int( $default ) ) ) - { - $options[$key] = 0; - } - } - } - - $this->options = $options; - - /* set up server array from hosts config var */ - $this->split_hosts(); - - $this->all_options[ $this->options_key ] = $this->options; - } - } -} - -/** - * instantiate the class - */ -$wp_nmc = new WPFFPC(); - - -?> + +Author URI: http://petermolnar.eu/ +License: GPLv3 +*/ + +/* Copyright 2010-2013 Peter Molnar ( hello@petermolnar.eu ) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 3, as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +include_once ( 'wp-ffpc-class.php' ); + +$wp_ffpc_defaults = array ( + 'hosts'=>'127.0.0.1:11211', + 'expire'=>300, + 'invalidation_method'=>0, + 'prefix_meta' =>'meta-', + 'prefix_data' =>'data-', + 'charset' => 'utf-8', + 'log_info' => false, + 'log' => true, + 'cache_type' => 'memcached', + 'cache_loggedin' => false, + 'nocache_home' => false, + 'nocache_feed' => false, + 'nocache_archive' => false, + 'nocache_single' => false, + 'nocache_page' => false, + 'sync_protocols' => false, + 'persistent' => false, + 'response_header' => false, +); + +$wp_ffpc = new WP_FFPC ( 'wp-ffpc', '1.0', 'WP-FFPC', $wp_ffpc_defaults, 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC' ); + + +?>