Press "Enter" to skip to content

Blogging: Cache Remote

[Cache Remote]For a number of months now, I’ve been running a little script on my website to control my blog rolls. Basically, a blog roll is a list of sites that I read regularly (they appear on the right hand side of the blog by the way) and “updates” on them are indicate (in my case with bold text and stars).

However, to ensure the blog rolls stay up to date, I use a service called blogrolling which provides a Javascript or PHP file for you to include in your site and will, therefore, display a list of recently updated blogs of your choosing. But what happens if you get nearly 600 visitors a day a day – that mean every time somebody reads your blog, they’ve then get to fetch the extra file from blogrolling and use up their bandwidth (which, as the owner of blogrolling realised can be quite a lot with popular blogs). Therefore, in the sake of conserving bandwidth, I’ve written a PHP script called “cacheremote” which will help take the load off the remote server.

Oh – and the script has an added bonus. If, when it comes to “refresh time”, the blogrolling server is unavailable for any reason, then your blogroll will still be displayed!

Read on for details and to download it… (currently cacheremote v0.05)

Before proceeding, I thought I’d best warn you that “cacheremote” is a very “quick” script and comes with no guarantee at all, and hardly any documentation – therefore you use it at your own risk! You are free to distribute the code, but please keep in the little copyright message – if you make any changes to the code (other than documented here), please send them back to me so I can release the next version to the public without having to worry about “code forking”. Oh – and you aren’t obliged to acknowledge if you are using this script or not: but if you would like to put “Using cacheremote by Richy” with a link to this entry from somewhere on your blog (even in a single post), it would be appreciated (as I like to think I’m famous 😉 ).

Anyway, on with the instructions:

Step 1 is to download cacheremote (it’s a PHP text file).

Step 2 is to configure it. Sounds complication, but just open the file up in Notepad, EditPlus, WordPad yadda yadda and look at it. You’ll see at the very top of the file the following code, which I’ll now annotate for you:

<!– START OF BLOGROLLING CODE –>

Standard comment 🙂

<div class=”sidetitle”>BlogRoll<br />

Quick indication of what this section is for (it’ll be displayed on your blog)

<strong>*</strong>= Updated in last 6 hours<br />

Indicates to the end user/visitor what a “updated link” looks like and how often I set the update to within the blogrolling configuration.

<a href=”javascript:void(rollpop=window.open(‘http://www.blogrolling.com/add_links_pop.phtml?u=https://blog.rac.me.uk/&t=Richy\’s Random Ramblings’,’rollit’,’scrollbars=no,width=475,height=350,left=75,top=175,status=yes,resizable=yes’));rollpop.focus();”>Blogroll Me!</a></div>

Standard “Blogroll Me!” link.

<div class=”side”>

Formatting code

<?php
cacheremote(“/home/blog/sections/cachedblogroll.html”,
“http://rpc.blogrolling.com/display_raw.php?r=c34e639f5e8c7ed053e92b7e472b388b”,
15);
?></div>

And the start of the magic (i.e. the bit you HAVE to change). The first line (the “/home/blog/sections/cachedblogroll.html” section) indicates where in your webspace cacheremote should store the cached file. Some good locations may be /var/www/html/cachedblogroll.html or /home/mylogin/cachedblogroll.html – you can call the actual file whatever you like, I’ve just called mine “cachedblogroll.html” as it will be basically HTML content and that it is a cached blogroll file (obvious isn’t it). You could call it “flibblepenguinahoy.txt” but you could end up puzzling about what a flibblepenguin is…

The next line – http://rpc.blogrolling.com/display_raw.php?r=c34e639f5e8c7ed053e92b7e472b388b – indicates the URL where the content originates from. Blogrolling members are best using the “PHP code” line which can be got by logging into blogrolling, selecting “Get code” and then scrolling down to where it says “PHP” and just copying the URL shown in the text box. If you are using cacheremote for non-blogrolling purposes, I’m sure you can figure out where to change this URL to (for example you could change it to the BBC’s RSS feed if you wanted).

Finally, the last section the digits 15 indicates the “freshness” level in minutes. A setting of 15 would indicate that after 15 minutes, the server should attempt to fetch a new copy of the file from the remote server. If you are thinking of setting it to something like “1” (1 minute), then don’t – the blogrolling database only updates every 5 minutes (so 4 out of 5 times you wouldn’t be getting any “new” content anyway), and a short time span is just a waste.

Step 3: Installation. Ok, here’s the catch – you’ve got to be running PHP on your website already. If you’re running MT-RefSearch, then you are definitely “ready to roll”, otherwise you may have to get your blog to use PHP before hand.

Ok, if you know you do use PHP, then you’ve just got to install the script. Upload it to your webspace (called, for example, blogroll.php) and then add the following line into your template file:

<?php include_once “/home/blog/blogroll.php”; ?>

(of course, amending it to suit your configuration). Rebuild the template and check your site – you should see a very short initial delay as the script fetches the blogroll from the remote server, but then away you go!

If you are interested in how it actually works, have a look at the “cacheremote” function – if you don’t understand it, don’t touch it the section starting “function cacheremote(…”

Any problems, feel free to leave a comment and I’ll try and get back to you. Remember that email addresses are hidden from view – so don’t be afraid to leave your real one (I’ll only use it for answering your question etc).

8 Comments

  1. Wow – great work!

    🙂

  2. Looks good. I’ll look into it once I’ve got everything else sorted :).

  3. Hiya Richy – tried to implement this today but I’m getting this:

    Warning: fopen(“/home/virtual/site299/fst/var/www/html/cachedblogroll.html”, “w”) – Permission denied in /home/virtual/site299/fst/var/www/html/cacheremote.php on line 64

    I followed everything else correctly. Any ideas?

  4. Hi Neil:

    Try just uploading a file called “cachedblogroll.html” to your webspace – it’s just a case where server software is being secure and stopping the creation of arbitrary files by scripts (if you change the file permissions on the directory it may be able to create the file itself, but just uploading a “holding file” would be easiest). You may need to wait 1/5/15 minutes (depending on your config of Cache Remote) for it to update the temp cached file with the real data though.

    If it still doesn’t work correctly – try chmodding the file to be user+group writable.

    Let me know what works – if you don’t get any joy, try contacting your web host (I’m sure their helpdesk people will be able to help with this problem 😉 ).

  5. CacheRemote

    I’ve hooked in Richy C’s CacheRemote tool to cache the blogrolls on my server. This means that instead of contacting the BlogRolling server every time the page is loaded, it is only contacted every 15 minutes, thus putting much less…

  6. Harry Harry

    Hi Richy,

    I’ve tried to install this on http://www.csmager.co.uk/index.shtml – but as you can see the php code is not being executed at all. I’m not sure how to turn this on – any ideas? The server claims to be running PHP, version 4.3.1.

    Thanks 🙂

  7. Looks good – I’ll download and see how easy it is to put it as an asp module….Shouldn’t be too hard – just need the time!

  8. Jeff Jeff

    Hi Richy,

    Your caching solution sounds ideal! So much easier than all the others.

    The problem I’m having is that I’m trying to integrate it with zFeeder. (Another great free program!) {http://zvonnews.sourceforge.net/zfeeder.php} I have numerous RSS news feeds and would love to cache them for obvious reasons. However I’m having a little difficulty figuring how to get the two to work together.

    I’ve followed your instructions. zFeeder allows me to configure it to allow off-line refreshing, and they give you a file and parameters to use in a chron or php script, which I’ve done. However, the file I created in the zFeeder cache folder, (your cachedblogroll.html file) stays empty.

    Any thoughts or suggestions? I’d love to be able to use your Cache Remote!

    Thanks,
    Jeff

Comments are closed.