Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first working version of Wordpress plug-in

  • Loading branch information...
commit 695faef11aa4eb533cb241b755942a74f0c23d01 1 parent 131a3c5
@timwhitlock authored
View
20 LICENSE
@@ -0,0 +1,20 @@
+ Copyright (c) 2010 Tim Whitlock
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
View
16 README.md
@@ -3,16 +3,26 @@
PHP tools for working with Varnish reverse proxy cache.
* Authors: [Tim Whitlock](http://twitter.com/timwhitlock)
-* See http://varnish-cache.org/ for information about Varnish
+* See [varnish-cache.org](http://varnish-cache.org/) for information about Varnish
## Admin socket
-Currently this project comprises an admin socket class, which PHP applications can use to interface with the **varnishadm** program.
+This package includes an admin socket class, which PHP applications can use to interface with the **varnishadm** program.
Common tasks would include checking the health of caches and purging when site content needs refreshing.
+## Wordpress plug-in
+
+This package includes a Wordpress plug-in. See wordpress/README.md
+
+
## Todo
* varnishadm authentication
-* Add all short cut methods to commands listed below
+* Add short cut methods for all admin commands
* Sanitise admin command parameters, such as regexp
* HTTP tools
+* Drupal module
+
+## License
+
+The whole php-varnish package, is released under the MIT license, see LICENSE.
View
18 VarnishAdminSocket.php
@@ -73,13 +73,13 @@ function __construct( $host = '127.0.0.1', $port = 6082 ){
* @return string the banner, in case you're interested
*/
function connect( $timeout = 5 ){
- $this->fp = fsockopen( $this->host, $this->port, $errno, $errstr, $timeout );
+ $this->fp = fsockopen( $this->host, $this->port, $errno, $errstr, $timeout );
if( ! is_resource( $this->fp ) ){
// error would have been raised already by fsockopen
- throw new Exception( sprintf('Failed to connect to varnishadm on %s:%s', $this->host, $this->port));
+ throw new Exception( sprintf('Failed to connect to varnishadm on %s:%s; "%s"', $this->host, $this->port, $errstr ));
}
// set socket options
- stream_set_blocking( $this->fp, true );
+ stream_set_blocking( $this->fp, 1 );
stream_set_timeout( $this->fp, $timeout );
// connecting should give us the varnishadm banner with a 200 code
$banner = $this->read( $code );
@@ -117,7 +117,7 @@ public function command( $cmd, &$code, $ok = 200 ){
$response = $this->read( $code );
if( $code !== $ok ){
$response = implode("\n > ", explode("\n",trim($response) ) );
- throw new Exception( sprintf("%s\n - Command responded %d:\n > %s", $cmd, $code, $response) );
+ throw new Exception( sprintf("%s command responded %d:\n > %s", $cmd, $code, $response) );
}
return $response;
}
@@ -132,8 +132,14 @@ private function read( &$code ){
$code = 0;
// get bytes until we have either a response code and message length or an end of file
// code should be on first line, so we should get it in one chunk
- while ( ! feof($this->fp) ) {
- $response = fgets( $this->fp, 1024 );
+ while ( ! feof($this->fp) ) {
+ $response = fgets( $this->fp, 1024 );
+ if( ! $response ){
+ $meta = stream_get_meta_data($this->fp);
+ if( $meta['timed_out'] ){
+ throw new Exception(sprintf('Timed out reading from socket %s:%s',$this->host,$this->port));
+ }
+ }
if( preg_match('/^(\d{3}) (\d+)/', $response, $r) ){
$code = (int) $r[1];
$len = (int) $r[2];
View
8 example-admin.php
@@ -17,8 +17,8 @@
// open socket connection with your known host and IP
-$Sock = new VarnishAdminSocket( 'localhost', 6082 );
-$Sock->connect();
+$Sock = new VarnishAdminSocket( 'localhost', 8080 );
+$Sock->connect(1);
// Check that child is running. If varnish wasn't running at all, connect would have timed out
@@ -27,13 +27,15 @@
// stop it, and check again
-$Sock->stop();
+$Sock->stop();
+sleep(1);
$running = $Sock->status();
var_dump( $running );
// start it up again, and check
$Sock->start();
+sleep(1);
$running = $Sock->status();
var_dump( $running );
View
183 wordpress/wordpress.php → wordpress-plugin.php
@@ -1,59 +1,104 @@
<?php
-/*
+/**
Plugin Name: WordPress Varnish Admin
Plugin URI: http://github.com/timwhitlock/php-varnish/tree/master/php-varnish/wordpress
-Version: 0.1
-Author: <a href="http://twitter.com/timwhitlock">Tim Whitlock</a>
Description: A plugin enabling Wordpress to purge Varnish caches via the varnishadm program
+Version: 0.1
+Author: Tim Whitlock
+Author URI: http://twitter.com/timwhitlock
*/
+/**
+ * Test whether current request is proxied
+ * @return bool
+ */
+function wpv_is_proxied(){
+ return isset($_SERVER['HTTP_X_FORWARDED_FOR']) || isset($_SERVER['HTTP_X_VARNISH']);
+}
+
+
+
+/**
+ * Gets base URL of site according to *currently* serving host.
+ * This is required of you want to access origin server directly for debugging.
+ * @return string e.g. http://origin.example.com:8080
+ */
+function wpv_baseurl(){
+ static $baseurl;
+ if( ! isset($baseurl) ){
+ $hostname = $_SERVER['HTTP_HOST']; // <- includes :port
+ $protocol = empty($_SERVER['HTTPS']) ? 'http' : 'https';
+ $baseurl = $protocol.'://'.$hostname;
+ }
+ return $baseurl;
+}
+
+
+
+/**
+ * As above, this ensures that theme can be served by origin server directly
+ */
+function wpv_themeurl( $themes_baseurl, $site_baseurl, $theme_dir ){
+ return wpv_baseurl(). '/wp-content/themes';
+}
+
+
/** admin menu hook */
function wpv_admin_menu() {
- add_options_page( 'Varnish Admin Options', 'Varnish Admin', 'manage_options', 'wpv', 'wpv_admin_page');
+ add_options_page( 'Varnish Admin Options', 'Varnish Admin', 'manage_options', 'wpv-admin', 'wpv_admin_page');
}
/** admin page hook */
function wpv_admin_page(){
- if ( ! current_user_can('manage_options') ){
- wp_die( __('You do not have sufficient permissions to access this page.') );
- }
- if( isset($_POST['wpv']) ){
- update_option( 'wpv_clients', $_POST['wpv_clients'] );
- }
- $clients = get_option('wpv_clients') or $clients = '127.0.0.1:6082';
- ?>
- <div class="wrap">
- <h2>Configure one or more Varnish clients</h2>
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" enctype="application/x-www-form-urlencoded" id="wpvadmform">
- <fieldset>
- <label>Specify clients one per line, in format <em>host:port</em></label>
- <textarea name="wpv_clients" cols="30" rows="5" wrap="virtual"><?php echo esc_html($clients)?></textarea>
- </fieldset>
- <input type="submit" value="Save" name="wpv" />
- </form>
- </div>
- <?php
- // end of admin screen
+ include dirname(__FILE__).'/wordpress-plugin/wordpress-admin.php';
}
+/**
+ * Parse raw postdata because Wordpress is *insane* and forces addslashes
+ * Note: this doesn't parse array parameters like "foo[]=bar&foo[]=baz"
+ * @param string
+ * @return array
+ */
+function wpv_postdata( $raw, $pair_sep = '&', $arg_sep = '=' ){
+ $data = array();
+ foreach( explode($pair_sep, $raw) as $pair ){
+ @list($key, $val) = explode($arg_sep, $pair);
+ $key = urldecode($key);
+ $val = urldecode($val);
+ if( isset( $data[$key] ) ){
+ if( ! is_array($data[$key]) ){
+ $data[$key] = array( $data[$key] );
+ }
+ $data[$key][] = $val;
+ }
+ else{
+ $data[$key] = $val;
+ }
+ }
+ return $data;
+}
+
+
/**
* parse client options saved as raw text
*/
-function wpv_get_clients(){
- $raw = get_option('wpv_clients');
+function wpv_get_clients( $raw = null ){
+ if( is_null($raw) ){
+ $raw = get_option('wpv_clients');
+ }
if( ! $raw ){
return;
}
$clients = array();
- foreach( preg_split('/[^[a-z]\d\.\:\-]+/i', trim($raw), -1, PREG_SPLIT_NO_EMPTY ) as $line ){
+ foreach( preg_split('/[^a-z0-9\.\:\-]+/i', trim($raw), -1, PREG_SPLIT_NO_EMPTY ) as $line ){
$clients[] = explode(':', $line, 2 );
}
return $clients;
@@ -61,29 +106,36 @@ function wpv_get_clients(){
+/**
+ * instantiate an admin socket
+ * @return VarnishAdminSocket
+ */
+function wpv_admin_socket( $host, $post ){
+ if( ! class_exists('VarnishAdminSocket') ){
+ include dirname(__FILE__).'/VarnishAdminSocket.php';
+ if( ! class_exists('VarnishAdminSocket') ){
+ throw new Exception('Failed to include VarnishAdminSocket class');
+ }
+ }
+ return new VarnishAdminSocket( $host, $post );
+}
+
+
/**
* Send multiple purge commands to all varnishadm sockets
*/
function wpv_purge_urls( array $urls ){
- // @todo get server params from config
- $hostpattern = get_option('wpv_host_pattern');
- $clients[] = wpv_get_clients();
+ $hostpattern = get_option('wpv_host_pattern','');
+ $clients = wpv_get_clients();
if( ! $clients ){
return;
}
- // ensure admin class is available
- if( ! class_exists('VarnishAdminSocket') ){
- include dirname(__FILE__).'/../VarnishAdminSocket.php';
- if( ! class_exists('VarnishAdminSocket') ){
- throw new Exception('Failed to include VarnishAdminSocket class');
- }
- }
// iterate over all available sockets
foreach( $clients as $client ){
try {
list( $host, $port ) = $client;
- $Sock = new VarnishAdminSocket( $host, $port );
+ $Sock = wpv_admin_socket( $host, $port );
$Sock->connect();
if( ! $Sock->status() ){
throw new Exception( sprintf('Varnish server stopped on host %s:%d', $host, $port ) );
@@ -93,11 +145,9 @@ function wpv_purge_urls( array $urls ){
try {
$expr = sprintf('req.url ~ "%s"', $url );
if( $hostpattern ){
- $expr .= sprintf(' && req.host.http ~ "%s"', $hostpattern );
+ $expr .= sprintf(' && req.http.host ~ "%s"', $hostpattern );
}
$Sock->purge( $expr );
- // purge ok - temporary logging for debug
- error_log('wpv purged: '.var_export($expr,1), 0 );
}
catch( Exception $Ex ){
trigger_error( $Ex->getMessage(), E_USER_WARNING );
@@ -120,10 +170,14 @@ function wpv_purge_urls( array $urls ){
* Collect URLs to purge relating to a post
*/
function wpv_edit_post_action( $postid ){
+ if( ! $postid ){
+ // I don't know why this would be empty, but it sometimes is
+ return;
+ }
global $wpv_to_purge;
$uri = parse_url( get_permalink($postid), PHP_URL_PATH );
if( ! $uri ){
- trigger_error('Failed to get permalink path from post with id '.$postid, E_USER_WARNING);
+ trigger_error('Failed to get permalink path from post with id '.var_export($postid,1), E_USER_WARNING);
return;
}
// common, home page and all feeds
@@ -157,10 +211,13 @@ function wpv_edit_post_action( $postid ){
* Collect URLs to purge relating to a comment
*/
function wpv_edit_comment_action( $commentid ){
+ if( ! $commentid ){
+ return;
+ }
$comment = get_comment($commentid) and
$postid = $comment->comment_post_ID;
- if( ! isset($postid) ){
- trigger_error('Failed to get post from comment with id '.$commentid, E_USER_WARNING);
+ if( empty($postid) ){
+ trigger_error('Failed to get post from comment with id '.var_export($commentid), E_USER_WARNING);
return;
}
// purge post that comment is on
@@ -182,29 +239,35 @@ function wpv_purge_on_shutdown(){
-// invoke purge actions when posts and comments are edited
-add_action( 'edit_post', 'wpv_edit_post_action', 99 );
-add_action( 'deleted_post', 'wpv_edit_post_action', 99 );
-add_action( 'comment_post', 'wpv_edit_comment_action', 99 );
-add_action( 'edit_comment', 'wpv_edit_comment_action', 99 );
-add_action( 'trashed_comment', 'wpv_edit_comment_action', 99 );
-add_action( 'untrashed_comment', 'wpv_edit_comment_action', 99 );
-add_action( 'deleted_comment', 'wpv_edit_comment_action', 99 );
-
-
-// hold all URLs in a global and purge on shutdown - this is designed to avoid duplicate purges.
-// yes, I know globals are nasty, but this is Wordpress we're dealing with here.
-$GLOBALS['wpv_to_purge'] = array();
-add_action( 'shutdown', 'wpv_purge_on_shutdown', 0 );
-
+if( get_option('wpv_enabled') ){
+ // invoke purge actions when posts and comments are edited
+ add_action( 'edit_post', 'wpv_edit_post_action', 99, 1 );
+ add_action( 'deleted_post', 'wpv_edit_post_action', 99, 1 );
+ add_action( 'comment_post', 'wpv_edit_comment_action', 99, 1 );
+ add_action( 'edit_comment', 'wpv_edit_comment_action', 99, 1 );
+ add_action( 'trashed_comment', 'wpv_edit_comment_action', 99, 1 );
+ add_action( 'untrashed_comment', 'wpv_edit_comment_action', 99, 1 );
+ add_action( 'deleted_comment', 'wpv_edit_comment_action', 99, 1 );
+
+ // hold all URLs in a global and purge on shutdown - this is designed to avoid duplicate purges.
+ // yes, I know globals are nasty, but this is Wordpress we're dealing with here.
+ $GLOBALS['wpv_to_purge'] = array();
+ add_action( 'shutdown', 'wpv_purge_on_shutdown', 0 );
+}
// register admin pages
add_action('admin_menu', 'wpv_admin_menu');
+// filter base URLs when accessing directly
+if( ! wpv_is_proxied() ){
+ add_filter('pre_option_siteurl', 'wpv_baseurl', 0 );
+ add_filter('pre_option_home', 'wpv_baseurl', 0 );
+ add_filter('theme_root_uri', 'wpv_themeurl', 0, 3 );
+}
-// hack REMOTE_ADDR, because neither Wordpress or Akismet check for proxy
+// hack REMOTE_ADDR, because neither Wordpress nor Akismet check for proxy
// note that Varnish should set this header before passing to backend
if( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ){
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
View
16 wordpress-plugin/README.md
@@ -0,0 +1,16 @@
+# Wordpress plugin for Varnish
+
+This plug-in uses a varnishadm socket connection to purge pages when content is altered.
+This includes editing of posts and addition of new comments.
+
+Place the whole php-varnish package in your wp-content/plugins directory and enable it in the admin area.
+You can configure one of more Varnish front ends at *settings > Varnish admin*.
+
+The sample VCL file wordpress.vcl is aggresive in maximizing cacheable pages.
+Only logged in admin users' cookies are allowed through.
+
+## License
+
+This plug-in, as with the rest of the php-varnish package, is released under the MIT license.
+
+
View
147 wordpress-plugin/wordpress-admin.php
@@ -0,0 +1,147 @@
+<?php
+/**
+ * Varnish admin page
+ * included in wpv_admin_page function
+ * @todo make nice tabbed interface
+ */
+
+if ( ! current_user_can('manage_options') ){
+ wp_die( __('You do not have sufficient permissions to access this page.') );
+}
+
+// Dodge Wordpress's rediculous magic quotes nonsense
+$postdata = wpv_postdata( file_get_contents('php://input') );
+
+// save posted settings
+if( isset($postdata['wpv_save']) ){
+ update_option( 'wpv_clients', $postdata['wpv_clients'] );
+ update_option( 'wpv_host_pattern', $postdata['wpv_host_pattern'] );
+ update_option( 'wpv_enabled', ! empty($postdata['wpv_enabled']) );
+}
+
+// perform manual purge
+else if( isset($postdata['wpv_purge']) ){
+ $purge = $postdata['wpv_purge_pattern'];
+ $timeout = $postdata['wpv_timeout'] or $timeout = 3;
+ foreach( wpv_get_clients() as $client ){
+ list( $host, $port ) = $client;
+ try {
+ $Sock = wpv_admin_socket( $host, $port );
+ @$Sock->connect( $timeout );
+ $Sock->purge( $purge );
+ $purges[$host.':'.$port] = 'Purged';
+ }
+ catch( Exception $Ex ){
+ $purges[$host.':'.$port] = 'Error: '.$Ex->getMessage();
+ }
+ }
+}
+
+// perform ping / diagnostics
+else if( isset($postdata['wpv_ping']) ){
+ $pingclients = $postdata['wpv_clients'];
+ $timeout = $postdata['wpv_timeout'] or $timeout = 3;
+ foreach( wpv_get_clients($pingclients) as $client ){
+ list( $host, $port ) = $client;
+ try {
+ $Sock = wpv_admin_socket( $host, $port );
+ @$Sock->connect( $timeout );
+ $ping[$host.':'.$port] = $Sock->status() ? 'Running :)' : 'Stopped, but responding';
+ }
+ catch( Exception $Ex ){
+ $ping[$host.':'.$port] = 'Error: '.$Ex->getMessage();
+ }
+ }
+}
+
+// get current raw clients string setting
+$enabled = get_option('wpv_enabled');
+$clients = get_option('wpv_clients', '127.0.0.1:6082');
+
+// get current hostpattern setting
+$hostpattern = get_option('wpv_host_pattern','');
+if( ! $hostpattern && preg_match('![^\./]+\.[a-z]+!i',get_option('siteurl'),$r) ){
+ $hostpattern = str_replace('.','\\\\.',$r[0]).'$';
+}
+
+// defaults that may not have been set
+isset($pingclients) or $pingclients = $clients;
+isset($timeout) or $timeout = 3;
+isset($purge) or $purge = 'req.url ~ "^/$"'.($hostpattern ? ' && req.http.host ~ "'.$hostpattern.'"' : '');
+
+?>
+
+
+ <div class="wrap">
+ <h2>Varnish admin</h2>
+ <h3>Configure Varnish clients</h3>
+ <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" enctype="application/x-www-form-urlencoded">
+ <fieldset>
+ <label>
+ <input type="checkbox" name="wpv_enabled" value="1"<?php echo $enabled?' checked="checked"':''?> />
+ Enable purging when content changes
+ </label>
+ </fieldset>
+ <br />
+ <fieldset>
+ <label for="f_wpv_host_pattern">Specify a host name pattern for purge commands</label> <br />
+ req.http.host ~ <input type="text" name="wpv_host_pattern" id="f_wpv_host_pattern" value="<?php echo esc_html($hostpattern)?>" size="32" />
+ </fieldset>
+ <br />
+ <fieldset>
+ <label for="f_wpv_clients">Specify Varnish clients separated by spaces (<em>host:port</em>) </label> <br />
+ <input type="text" name="wpv_clients" id="f_wpv_clients" value="<?php echo esc_html($clients)?>" size="100" />
+ </fieldset>
+ <br />
+ <input type="submit" value="Save config" name="wpv_save" />
+ </form>
+
+ <a name="ping"></a>
+ <?php if( ! empty($ping) ): ?>
+ <h3>Ping results</h3>
+ <?php foreach( $ping as $client => $result ):?>
+ <div>
+ <strong><?php echo esc_html($client)?></strong>
+ <pre><?php echo esc_html($result)?></pre>
+ </div>
+ <?php endforeach?>
+ <?php endif?>
+
+ <h3>Ping Varnish clients</h3>
+ <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" enctype="application/x-www-form-urlencoded">
+ <fieldset>
+ <input type="text" name="wpv_clients" id="f_wpv_clients" value="<?php echo esc_html($pingclients)?>" size="100" />
+ </fieldset>
+ <fieldset>
+ timeout: <input type="text" name="wpv_timeout" id="f_wpv_timeout" value="<?php echo esc_html($timeout)?>" size="4" /> secs
+ </fieldset>
+ <input type="submit" value="Ping" name="wpv_ping" />
+ </form>
+
+ <a name="purge"></a>
+ <?php if( ! empty($purges) ): ?>
+ <h3>Purge results</h3>
+ <?php foreach( $purges as $client => $result ):?>
+ <div>
+ <strong><?php echo esc_html($client)?></strong>
+ <pre><?php echo esc_html($result)?></pre>
+ </div>
+ <?php endforeach?>
+ <?php endif?>
+
+ <h3>Manual purge</h3>
+ <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" enctype="application/x-www-form-urlencoded">
+ <fieldset>
+ <input type="text" name="wpv_purge_pattern" id="f_wpv_purge" value="<?php echo esc_html($purge)?>" size="100" />
+ </fieldset>
+ <fieldset>
+ timeout: <input type="text" name="wpv_timeout" id="f_wpv_timeout" value="<?php echo esc_html($timeout)?>" size="4" /> secs
+ </fieldset>
+ <input type="submit" value="Purge" name="wpv_purge" />
+ </form>
+
+ <h3>Help</h3>
+ <p>Tweet <a href="http://twitter.com/timwhitlock" target="_blank">@timwhitlock</a> and I'll try to help</p>
+
+ </div>
+
View
94 wordpress-plugin/wordpress.vcl
@@ -0,0 +1,94 @@
+
+backend origin {
+ .host = "localhost";
+ .port = "8080";
+}
+
+
+sub vcl_recv {
+ # only using one backend
+ set req.backend = origin;
+
+ # set standard proxied ip header for getting original remote address
+ set req.http.X-Forwarded-For = client.ip;
+
+ # logged in users must always pass
+ if( req.url ~ "^/wp-(login|admin)" || req.http.Cookie ~ "wordpress_logged_in_" ){
+ return (pass);
+ }
+
+ # always pass through posted requests and those with basic auth
+ if ( req.request == "POST" || req.http.Authorization ) {
+ return (pass);
+ }
+
+ # else ok to fetch a cached page
+ unset req.http.Cookie;
+ return (lookup);
+}
+
+
+
+sub vcl_fetch {
+
+ # remove some headers we never want to see
+ unset beresp.http.Server;
+ unset beresp.http.X-Powered-By;
+
+ # only allow cookies to be set if we're in admin area - i.e. commenters stay logged out
+ if( beresp.http.Set-Cookie && req.url !~ "^/wp-(login|admin)" ){
+ unset beresp.http.Set-Cookie;
+ }
+
+ # don't cache response to posted requests or those with basic auth
+ if ( req.request == "POST" || req.http.Authorization ) {
+ return (pass);
+ }
+
+ # Trust Varnish if it says this is not cacheable
+ if ( ! beresp.cacheable ) {
+ return (pass);
+ }
+
+ # only cache status ok
+ if ( beresp.status != 200 ) {
+ return (pass);
+ }
+
+ # else ok to cache the response
+ set beresp.ttl = 24h;
+ return (deliver);
+}
+
+
+
+sub vcl_deliver {
+ # add debugging headers, so we can see what's cached
+ if (obj.hits > 0) {
+ set resp.http.X-Cache = "HIT";
+ }
+ else {
+ set resp.http.X-Cache = "MISS";
+ }
+ # remove some headers added by varnish
+ unset resp.http.Via;
+ unset resp.http.X-Varnish;
+}
+
+
+
+sub vcl_hash {
+ set req.hash += req.url;
+ # altering hash so subdomains are ignored.
+ # don't do this if you actually run different sites on different subdomains
+ if ( req.http.host ) {
+ set req.hash += regsub( req.http.host, "^([^\.]+\.)+([a-z]+)$", "\1\2" );
+ } else {
+ set req.hash += server.ip;
+ }
+ # ensure separate cache for mobile clients (WPTouch workaround)
+ if( req.http.User-Agent ~ "(iPod|iPhone|incognito|webmate|dream|CUPCAKE|WebOS|blackberry9\d\d\d)" ){
+ set req.hash += "touch";
+ }
+ return (hash);
+}
View
2  wordpress/README.md
@@ -1,2 +0,0 @@
-# Wordpress plugin for Varnish
-
Please sign in to comment.
Something went wrong with that request. Please try again.