Latest Entries

Linux Kernel, Modules and Plugins

Here are some views expressed by Linus Torvalds about the Linux kernel, plugins and how he thinks about derivative work. Very relevant to what I said about plugin interfaces and user space.

So, do themes and plugins serve a system-level or a user-level function?

p.s. Some have compared WordPress plugin and theme API to the way Linux loads kernel modules, when in fact relating it to system call interface (SCI) would be more appropriate.

GPL Sockets

It is interesting how thinking and understanding of ideas change over time. This morning I woke up and started reading the GPL licence with the intent to take another look at what it actually stands for.

I have come to conclusion that its purpose is to give everyone the freedom to do whatever they want with my work as long as they retain the freedom to derive from it.

With every software there are only two things one can do with it — either run it or modify it. By applying the GPL licence to my original work I am making sure that these two things can always happen and nobody can take those freedoms away. Read more »

Location Aware Login Prompt

Define your home as a GPS location +/- 50 m. If you are within that area, you don’t have to enter the password. If you are outside that area, you are requested to select three images in the right order from a grid of nine images. If that fails, you are requested to enter the password.

This would be extremely useful for all the tablets out there.

Automatic Updates for Plugins and Themes Hosted Outside WordPress Extend

Here are two sample scripts along with an API to provide automatic updates for plugins and themes you host on your own server.

Inside /api you’ll find index.php which processes all the update requests. You should place this in something like http://updates.example.com and update $api_url in /plugin/test-plugin-update/test-plugin-update.php and /theme/portfolio-racer/inc/updates.php accordingly. If you activate these sample plugins without changing API URL, updates will be checked against my test server. If you decide to update, both plugin and theme will be replaced with exactly the same version of each.

AJAX Cache Purge Cookie Plugin

This plugin sets a “version” cookie of your site’s content, which can be used for time-based cache invalidation, as the cookie is checked and updated (if necessary) on each page request through a single AJAX request.

Download: ajax-cache-purge.zip (June 26, 2010)

Installation

Please note that this plugin is intended for people who run their own servers.

  1. Upload and enable the plugin.
  2. Add the value of wp_cache_key_cookie to the cache key.

Nginx Example

fastcgi_cache_path 	/var/www/cache  levels=1:2
			keys_zone=wp-cache:10m
			inactive=2m max_size=2000m;
fastcgi_temp_path 	/var/www/cache/tmp;
server {
	# other config options
	location ~ \.php$ {
		# Cookie is supplied by the plugin
		set $wp_cache_key_cookie 0;
		if ($http_cookie ~* "wp_cache_key_cookie[^=]*=([^;]+)(;|$)") {
			set $wp_cache_key_cookie wp_cache_key_cookie_$1;
		}
		set $wp_cache_key $scheme$host|$request_uri|args=$args$|$wp_cache_key_cookie;
		#add key in header for debugging
		#add_header	WP_KEY $osc_cache_key;
		fastcgi_cache 		wp-cache;
		fastcgi_cache_key 	$wp_cache_key;
	}
}

Laptop from Aboard the Shuttle Spacecraft

There is only one brand of laptops used aboard the space shuttlesIBM ThinkPad. In my opinion, they are the best laptops one can ever buy, mainly because of their unspoken hardware and famous red trackpoint mouse.

Several weeks ago the screen inverter of my Dell Latitude D820 laptop (which also has a trackpoint) failed and turned it into a desktop that can only be used with an external monitor. So I found a used IBM ThinkPad A31p (released in 2002), which is now running Ubuntu that supports every piece of hardware inside it. Although I won’t be carrying it around very often because it weights 3.45 kg (7.6 lb), I might make a sticker that says “Used Aboard the Shuttle Spacecraft” and look cool even with a laptop that old.

IBM ThinkPad A31p

Read more »

Standalone Script for Clearing APC Cache

After upgrading WordPress to a new version, you might need to clear the APC opcode cache. Here is a simple script that you can store in the root of your website, for example, clearapc.php:

if (function_exists('apc_clear_cache') && $_GET['pass'] == 'secret') {
        if (apc_clear_cache() && apc_clear_cache('user'))
                print 'All Clear!';
        else
                print 'Clearing Failed!';
        print '<pre>';
        print_r(apc_cache_info());
        print '</pre>';
} else {
        print 'Authenticate, please!';
}

Then call the script via http://example.com/clearapc.php?pass=secret

Instead of using ?pass=secret, you might well call the filename something that is hard to guess: clearapc93920.php

Chrome OS vs Android for Tablets

Android’s strength is cellular voice and data transfer and its low power consumption while Chrome OS has better support for various hardware architectures, and they are both based on the Linux kernel.

If you were to build a tablet that has a touch screen not bigger than 9 inches and a modern browser as its only application, GSM + data connection, instant startup and a batter life of 12 hours, which OS would you choose?

I can’t understand why Google needs Chrome OS. Is it only for devices that don’t have touchscreens?

Use AJAX for Cache Invalidation

Let’s have a site wide version number that is changed every time something is updated and cache needs to be invalidated. This number is stored in a simple text file. Cache keys are made up of Request-URI and this unique key, which is passed around in a cookie VERSION_NO.

On every page request javascript calls version.php?timestamp (which is never cached because of the timestamp), which using stat() reads the last modified timestamp of that text file and compares it to the value of VERSION_NO cookie. If they are different, a new cookie value is set, which in turn changes the cache key for all future requests, and the cache is invalidated.

The only thing I don’t know is how fast and resource hungry is the stat() call?

Update: or would it be better to use filemtime()? There is a comment which says that 1000 filemtime() calls take 0.0049 seconds, which I think is very reasonable.

Regarding the ‘Like’ Button

You can like something and there is nothing you have to do about it. It is an effortless act and there are no explanations required or expected. And people actually don’t care for what you like. They are interested in what you care for, because caring isn’t pointless, it means you take a stand.