If you have a useful feature that works with Boost and it will help others, please add it to this page or add a comment to have it rolled into the page.

Contents


back to top

Using rules and PHP to refresh changed pages in cache

Case: The website has mostly anonymous visitors and a few content changes every so often. Waiting on cron to run may not be the best solution if you want changes to be available for anonymous visitors immediately. On a website such as this you are taking advantage of the Boost timestamp function to rebuild only pages that have changed at each cron run. This Rules-PHP-Trick works hand in hand with that Boost function as it will immediately refresh the cache with the one page that has has changed, rather than rebuild the entire cache.

Enable this Boost function:
[X] Check database timestamps for any site changes. Only if there's been a change will boost flush the expired content on cron.

Solution: Download the rules module, unzip it and upload it to sites/all/modules. Goto: (Administer > Site building > Modules > List) to enable Rules and PHP filter, save the changes. Goto: (Administer > Rules > Triggered rules > Add a new rule). Give the new rule a label or name, choose an Event that will trigger the rule from the select list (Content is going to be saved), check mark the box [X] This rule is active and should be evaluated when the associated event occurs. and save the changes. In the next section, choose (Add an action). Use the select list and choose (Execute custom PHP code), click next. Add the following code in the PHP Code text box and click save. Note: The PHP delimiters <?php and ?>are not needed.

global $base_root, $base_path;
drupal_http_request($base_root . $base_path . 'cron.php');

Now each time you create or update a page and save it, a cron run is called and will refresh the cache with the one page that has been changed. Your website visitors will see the new page immediately. A really neat feature!

in Drupal 7:
To save on server resources by avoiding running cron, simply copy the contents of boost.module within its implementation of hook_cron() as the PHP code to run:

// Remove expired files from the cache.
global $_boost;

// This was not invoked in hook_init because of the quick check to
// avoid caching requests from the CLI
$_boost = boost_transform_url();

if (isset($_boost['base_dir']) && variable_get('boost_expire_cron', BOOST_EXPIRE_CRON)) {
  $count = _boost_rmdir($_boost['base_dir'], FALSE);
  watchdog('boost', 'Expired %count stale files from static page cache.', array('%count' => $count), WATCHDOG_NOTICE);
}


back to top

Using Boost with latest version of Authcache

Case: There is a slight chance Boost will not work with latest version of Authcache.

solution:To get around this issue.
Goto (admin/settings/performance/boost)
In Boost advanced settings, disable this setting:
[  ] Asynchronous Opperation: output HTML, close connection, then store static file.

Run php in the background. When a cached page is generated, this will allow for faster page generation; downside is the headers are not the standard ones outputted by drupal; sends "Connection: close" instead of "Connection: Keep-Alive".

I "borrowed" some code from authcache, so we now use the same output buffer hooking mechanism; Boost's is more "Aggressive" though. It sends the page to the browser & closes the connection, then saves it to the disk, allowing for a more responsive site when using boost. With this change, the end game has to be something like the proposed hook_alter_html module; one that all page caching modules can use; thus preventing interference, and improving performance when using multiple page caching solutions.


back to top

Dynamically load the who's online block

Case: For sites that like to use a cache to serve the full page (boost, Drupal core cache, ect...), but still would like to have more dynamic content in a block; loading of blocks via ajax is a good way to accomplish this.

Solution: The simple way to do it, for one or 2 blocks it works. For anything more then that it would probably have a negative impact since it's doing a full bootstrap for each block.
More information and examples on this, see this page on Drupal Groups

example.php

<?php
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$block = module_invoke('user', 'block', 'view', 3);
print $block['content'];
?>

Place this HTML in a new block

<div id="who-online">
</div>
<script>
$('#who-online').load('/example.php');
</script>


back to top

Drush integration with Boost

Case: I need to run cron twice hourly (large amount of aggregated content). This becomes problematic with a one hour cache lifetime. If an expired cache clear was integrated into Drush, this would facilitate a periodic cron job to clear the stale files.

Solution: Project provision_boost
From the project page:
The provision boost module provides Drush hooks to automatically setup multi-site Drupal instances (or single sites) with the Boost module. It takes care of all the nitty-gritty configuration fixes that need to be applied in the backend so it works.

It is specifically aimed towards the Aegir project and therefore depends on the provision backend and expects the Aegir environment to be functional.

Additional cron modules that may help:
http://www.opensourcery.com/blog/dylan-tack/choosier-cron-runs
http://drupal.org/project/supercron
http://drupal.org/project/elysia_cron


back to top

Serve cached pages from an Apache mirror using rsync

This useful to run a small server cluster or a mirror. Boost will run as normal on the host server and the cache will be regularly transferred by rsync to the mirror(s). The Boost cache will be served using the boost .htaccess copied to the mirror.

Setup the host server:
Configure rsync at /etc/rsync.conf and add this to the file:

max connections = 1
  log file = /var/log/rsync.log
  timeout = 300
       
  [cache]
  comment = boost cache
  path = /var/www/example.com/cache/normal/example.com
  read only = yes
  list = no
  uid = nobody
  gid = nogroup

Set up the mirror server:
It's good to start with a full copy of the cache directory and the Boost htaccess file. Just copy it to the mirror server in the root folder.

Set to crontab to run regularly with:
/usr/bin/rsync -aqz --delete rsync://drupal.server.example.com/example-cache /var/www/example.mirror/cache/normal/example.com/

If you want other stuff running on the mirror, a virtual host will work to separate the requests and serve the cached content if it exists and the user is anonymous, add a proxy to override the virtual host for the other content.

<Directory /var/www/example.com/>
    AllowOverride all
</Directory>

ProxyRequests Off

<Proxy *>
  Order deny,allow
  Allow from all
</Proxy>

ProxyPass /index.php http://drupal.server.example.com/index.php
ProxyPassReverse /index.php http://drupal.server.example.com/index.php


back to top

Including dynamic blocks in a static page

See: AJAX Loading of any Block and Banners in boost

back to top

Boost and Ubercart

Since Boost 6.x-1.20, the boost settings has an option to "DISABLE Exit () inside of Boost _exit." This may help in some cases where the 'add to cart' fails.

See: #679422: hook_exit() causes Ubercart "Add to Cart" to fail

We need more feedback/testing to determine whether we should make this a default option when Ubercart is enabled.

back to top

Boost and Persistent Login

If you are using the persistent_login module, please refer to the following issue: #833410: Add persistent login support for apache2 - our solution here.

Comments

dadderley’s picture

I had a problem with a print current date script in a block that was caching.
I modified your example and use it to load a script that prints out the current date.
Works nicely, thanks.

<div id="date-f">&nbsp;</div>
<script>
$('#date-f').load('/sites/all/themes/nwacv2/date-f.php');
</script>
spflanze’s picture

In order for "Execute custom PHP code" to be found in the "Add an action's" select list the "php filter" must be enabled. It is disabled by default.

btopro’s picture

does this page really suggest using the PHP input filter to make a cron call without a key involved? This is horrible.