Last updated March 4, 2010. Created by dbeall on September 21, 2009.
Edited by sillygwailo. Log in to edit this page.
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
- Refresh pages with rules and PHP
- Using Boost with Authcache
- Dynamically load the who's online block
- Drush integration with Boost
- Apache mirror using rsync and Boost
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!
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.
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.
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>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
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 = nogroupSet 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
Comments
Loading dyanmic content so it will not cache using ajax
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"> </div><script>
$('#date-f').load('/sites/all/themes/nwacv2/date-f.php');
</script>
I get an error saying "The
I get an error saying "The code has to always return a boolean value." when I try to add the PHP snippet as outlined above in "Using rules and PHP to refresh changed pages in cache." Any ideas or suggestions?
Orlando Salcedo
www.islandwebdevel.com
In order for "Execute custom
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.
Boost and new comments
I have a site with mostly anonymous users that are able to post comments (the site gets 10 - 15 comments per day). Will the Using-rules-and-PHP tip allow anonymous users to see new comments immediately?
content_refresh
http://drupal.org/project/content_refresh
For cases like you can no
For cases like you can no longer log in to your Drupal site what to do?
Gatwick Hotels
thnaks for the tip
i have solution with this trick on my page but have other page where see error of boost i disable boost on this but multiple page no founs en log db
messenger hotmail