Category Archives: Blogging

My custom Memcached WordPress Plugin

Something that I have found irritating about using WordPress for my blogging needs is its performance – or lack thereof! On a blog like Ideologics (that is mainly information based) rebuilding each page whenever it is viewed leads to an incredible waste of processing power.

Memcached was developed by the authors of LiveJournal, and can be used in many ways to optimise a website. My method is to simply cache an entire page’s HTML the first time it is viewed.

Now this isn’t a traditional plugin, so bear with me. The processing script is called memcache.php, and its content is as follows:

  // note that if you change this variable, the cache restarts!
  $memcache_sectext=md5('mysite'.date('YMd'));
  $memcached=false;

  // display a 'reset this page in cache' link at bottom of page?
  $allowreset=true;

  if (function_exists('memcache_connect')) {
    $memcached=true;
    $memcache=@memcache_connect('127.0.0.1',11211) OR $memcached=false;
  } else {
    $memcached=false;
  }

  function getCache($var_name) {
    global $memcached,$memcache,$memcache_sectext;
    if ($memcached)
      $var_value=$memcache->get($memcache_sectext.'_'.$var_name);
    else
      $var_value='';
    return $var_value;
  }
  function setCache($var_name,$var_value) {
    global $memcached,$memcache,$memcache_sectext;
    if ($memcached)
      $memcache->set($memcache_sectext.'_'.$var_name,$var_value);
  }

  $domain=$_SERVER['HTTP_HOST'];
  $uri=$_SERVER['REQUEST_URI'];

  if ((isset($_GET['recache'])) AND ($allowreset)) {
    setCache($_GET['recache'],'');
    header('location: '.$_GET['recache']);
    exit;
  }

  $html=getCache($uri);
  if ($html!=='caching') {
    if (strlen($html)>100) {
      echo $html;
      if ($allowreset) echo '<p align="center">This page was retrieved'
        .' from our cache. <a href="/memcache.php?recache='
        .urlencode($uri).'" ref="nofollow">Recompile this page</a>.</p>';
      exit;
    } else {
      setCache($uri,'caching');
      $html=file_get_contents('http://'.$domain.$uri);
      if (strlen($html)>100) {
        setCache($uri,$html);
        echo $html;
        if ($allowreset) echo '<p align="center">This page was retrieved'
          .' from our cache. <a href="/memcache.php?recache='
          .urlencode($uri).'" ref="nofollow">Recompile this page</a>.</p>';
        exit;
      } else {
        setCache($uri,'');
      }
    }
  }

I include this file in /index.php, like this:

define('WP_USE_THEMES', true);

include('memcache.php');

/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');

Any page that is viewed via index.php (that’s posts, category listings, the home page etc.) will be cached and served automatically by memcache.php. Really simple, isn’t it? The cache is reset every day, as to introduce any new content that is dynamic.

It is worth noting that if a cached copy of the requested page is available and served, that WordPress doesn’t even make a connection to the database – NO queries are executed. There is no method faster than this.

The downsides to this method:

  1. When you make a new post or edit an existing post, the changes won’t show up until the next day. To help resolve this, I added an option to reset individual pages in the cache. You can turn the option on and off with the variable $allowreset at the top of the script. The option to reset a page appears at the very end of the page. (I’d recommend disallowing /memcache.php to your robots.txt file too!)
  2. Every page in the cache appears like it would to a guest. Users cannot log in with this method – YET.

I may turn this into an actual plugin, but for now there’s no demand. If you have any comments or suggestions, my ears are wide open!

NOTE: If you were to receive a burst of traffic due to being digg’d or something, I have no doubt that this implementation of Memcached in WordPress would allow your server to take care of it with no problems.

Blogging posts produce ZERO AdSense clicks – PERIOD

After looking over my Analytics data for AdSense, I’ve realised that my blogging posts produce NO clicks. I won’t tell you how many impressions this is based on, but rest assured that my assumption is sound. This is clearly bringing my overall CTR down.

The ‘Computer Help’ category tends to be the only category that produces clicks, and so I have decided to only display ads on that category, as the ads offer no additional value to the user nor myself in other categories.

I’m going to be studying my Analytics data more closely to see if I can work out how to remove potentially useless impressions from pages depending on factors such as country, browser type, length of document. I recommend you all do the same, to avoid or remove smart pricing.

Does having standards make you a snob?

Recently I came across Everton’s post regarding lingscars.com – claiming it was the worst website ever! At first I laughed profusely, but soon came to realise that laughing at someone elses work and success is quite rude.

Ling responded to Everton with a snap of reality, reminding him that she shifts millions of pounds worth of cars every year, and people enjoy her site. In reality, she is quite successful, and if I were to choose a website to sell cars I probably wouldn’t be as daring as she is.

Which leads me to my question – does having standards make you a snob? At what cost do we adhere to standards?

Back in 2002, when I started BloopDiary.com, the site had a colourful appearances like crayons. It grew popular very quickly. Now days, it is somewhat bland in appearance. When it was colourful, it stood out from the other sites. I almost miss my awful colour scheme!

And look at other sites, such as PlentyOfFish.com, a hugely successful website with a layout that a 5 year old could design.

What Ling’s site, my site and Plenty Of Fish all have in common is one thing – the value they offer to the people that visit. Somewhere we get lost in design, and forget about what really matters. To be honest, when I’m looking for something on the web, I could care less about what the website looks like, as long as I can use it and it gives me what I want. I definitely don’t search Google and then drool over how a page looks.

I think we need to step out of our boxes for a while, and look in as a visitor before our collective ego explodes.

Eye On Silicon becomes Ideologics

Recently I’ve been getting back in to blogging. Part of blogging, that I’m sure is as true for newbies as it is for the experienced bloggers, is research. Researching how to best mesh your blog in with the blogosphere.

While I like the name Eye On Silicon, there are several downsides to it. One is the negative word Eye – sometimes AdSense assumes this is a keyword and posts advertisements offering contact lenses which is definitely off topic. Back in the days of web desing, I registered a domain called Ideologics, both .co.uk and .com.

The name Ideologics doesn’t bring forth any imaginative advertisements, it’s about as neutral as one can get. It’s also much older than the Eye On Silicon domain – by approximately 6 years – and will likely help with SEO. That’s a theory that will be put to the test as I keep an eye on my statistics.

Stay tuned.

PostLove Feature: Popular posts by category

Following the previous Editor’s Choice post regarding the correct use of categories in WordPress, I’ve made some small changes to PostLove.

Here’s a rundown:

  • When you’re reading a post, the PostLove widget will display the most popular posts from the categories specified in that post.
  • When you’re browsing a category’s index, the PostLove widget will display that category’s most popular posts.

It’ll be interesting to see how this serves my traffic.

The changes haven’t been published yet as I’m still testing them.

How to use WordPress categories to your advantage

As part of an effort to provide daily content, I’ve decided to start linking to posts that I consider great value to those who blog. I’ll be categorising these posts under one of the five head categories – but also inside a new category called Editor’s Choice.

Ironically, the first post in this category is all about categories.

Continue reading How to use WordPress categories to your advantage

Strategic ad positions for Google AdSense

If a visitor to your blog doesn’t see something – will they click it? No! If you’re monetising your blog by selling advertising space, make sure the space is visible – it gives value to your visitors, and value to the advertisers bidding for space on your site.

Scared that people won’t click the ads if you put them in a visible spot? Don’t be. Here’s some myths I’d like to dispel:

Continue reading Strategic ad positions for Google AdSense