Archive for April 2010

Apparatus 0.4

A new version of Apparatus is available. Previously I wrote about several new features that would be included in this version, however rather than further postpone a release, I’ve decided to hold off on those features until the next version. Version 0.4 incorporates a new theme, the latest version of tab override (which should resolve any browser compatibility issues), and various improvements and modifications.

Done with the BS

I have been using various shared hosting providers for several years now. In that time I have never renewed a hosting plan with any single provider; instead moving from one to another for various reasons. Before I go any further let me describe my needs with regard to hosting:

  1. Obviously one of my needs is to host this blog. I don’t get a huge amount of visitors (150 on an average day) so this isn’t much to ask for.
  2. I have a few other sites that are in development, most of them will never see the light of day. Their impact on server load is pretty much negligible.
  3. I develop PHP scripts on my local windows machine, but I often upload and run them on my host to make sure they’ll work in a linux production server.
  4. If I develop something for a client I usually demo it on my host.

That’s it. Nothing is mission critical and I don’t get a lot of traffic. This being the case you may be wondering why I move from host to host. After all, my needs aren’t very demanding. To be honest one of the reasons is that a renewal is almost always more expensive than switching to a new provider. You don’t have to look hard to find a discount, the catch is you have to pay full price when it is time to renew.  I wouldn’t mind paying a bit more though, if it weren’t for one thing: there is almost always something that I find dissatisfying: poor customer service, lack of features, lack of freedom, etc.

One thing that up until my last host was never an issue was server performance. As I mentioned my needs are fairly small, and I don’t mind a little downtime. The fact that I can pay a company money and not have them meet my relatively small amount of demand has scared me away from shared hosting forever. This is where the horror story portion of this article begins:

Up until my recent host switch I had been hosting with a company called MochaHost. The reason I chose them in the first place was related to one of my complaints about a previous host: lack of features. On paper MochaHost had everything I needed, and like virtually every shared hosting provider they had an uptime guarantee. In general these guarantees have a ton of loopholes and are not to be trusted, but in this particular case the guarantee was an outright lie. The quality of server I experienced was beyond terrible. I experienced frequent downtime usually lasting only for a short period (but long enough to be extremely annoying when you are trying to get something done). Half the time when my service wasn’t down it was very slow, often to the point where you might as well consider it to be downtime. This graph illustrates my point:

The graph is from Google Webmaster Tools and shows the amount of time spent download a page. It should be fairly easy to tell at which point I switched hosts. The site performance tool in Webmaster Tools also consistently rated this site as being slower than 90+ percent of other sites prior to the switch.

When I reported this downtime usually the response completely ignored the underlying issue. Generally some person would reply that it seems to be working now, without addressing the problem that IT WAS down and that this wasn’t the first time. The only thing good I can say about MochaHost was that their customer service was very responsive and helpful, provided they weren’t dodging questions about uptime and performance.

MochaHost was only the worst part of what was ultimately a bad trip through shared hosting land. In spite of not needing much in terms of performance, I was constantly disappointed with the features and level of flexibility of shared hosting. This led me to switch to VPS (Virtual Private Server). In case you are unaware, a VPS is somewhere between a shared host and a dedicated server. A server is divided between multiple user, but this is transparent to the user; the environment is effectively the same as that of a dedicated server.

This comes at a cost however, I’m paying twice as much as I did for shared hosting. What I get in exchange, however, is well worth it. In addition to getting better performance than you could hope for in a shared host, I have absolute freedom: I have root access and I can configure my server anyway I please, and I can install which ever software I choose. I was even given the choice of server location (I chose one in California). Of course the downside to absolute freedom is absolute freedom: I’m free to screw up anything I can and when I do there is no one to hold my hand. Having had plenty of experience screwing up my own machine I think I’m up to the challenge.

Another benefit of VPS is the dramatic decline in bullshit. Some shared hosts give you unlimited everything, which is bullshit for ‘we’ll decide when you’ve used too much bandwidth or storage’. Still others promise you more than they would ever let you use. The caps on my bandwidth and storage are both real and reasonable. In case you’re interested (Warning: Imminent blatant affiliate link drop) I’m using Linode. I paid about $220 for a year of service and so far I couldn’t be happier. A word of caution though: If you don’t know how to configure and manage a server, or don’t want to take the time and effort to learn, it may not be for you.

Update: A perfect example of what I mean by being free to screw up anything I can: When I was configuring this site in apache I forgot to set the server alias www.tinsology.net for the domain tinsology.net. For whatever reason all of the traffic from www.tinsology.net was getting redirected to a completely different domain: errordatabase.info, which is another site of mine hosted on the same server.

PHP Overloading

The lack of function overloading is one of my biggest complaints about PHP. If you’re not familiar with overloading, its a feature of some languages that allows you to defined multiple methods (or functions) with the same name, but taking different paramenters. In Java, for instance, methods are not identified solely by their name. Instead, functions are distinguished by their signature: their name, return type, number of parameters and their types. This allows you to do things like define multiple constructors for a class.

PHP not being a typed language, using parameter types and return types as part of a method or function signature is out of the question. You could, however, use the number of parameters. In my opinion, you should be able to do something like this:

class Foo {

	function __construct()
	{
		//constructor that takes no parameters
	}

	function __construct($param1)
	{
		//constructor that takes 1 parameter
	}

	function __construct($param1, $param2)
	{
		//constructor that takes 2 parameters
	}
}

If you did this, however, you would get an error message reading something like this: Fatal error: Cannot redeclare Foo::__construct. As unfortunate as this is, it is possible to devise a simple workaround, due to the fact that a method can be written to take an arbitrary number of parameters. The solution is to create a method that can take any number of parameters and have that method delegate to ‘helper’ methods:

class Foo {

	public function __construct()
	{
		$args = func_get_args(); //any function that calls this method can take an arbitrary number of parameters
		switch(func_num_args())
		{
			//delegate to helper methods
		case 0:
			$this->construct0();
		break;
		case 1:
			$this->construct1($args[0]);
		break;
		case 2:
			$this->construct2($args[0], $args[1]);
		break;
		default:
			trigger_error('Incorrect number of arguments for Foo::__construct', E_USER_WARNING);
		}
	}

	private function construct0()
	{
		//constructor that takes no parameters
	}

	private function construct1($param1)
	{
		//constructor that takes 1 parameter
	}

	private function construct2($param1, $param2)
	{
		//constructor that takes 2 parameters
	}

}

It might not be pretty, but using this method you will be able to call the constructor of Foo as if it were actually overloaded:

$x = new Foo();
$y = new Foo(1);
$z = new Foo(1, 2);

An alternative to this would be to use default parameters to determine what action to perform, but this method gets increasingly clumsy as the number of arguments grows.

Tab Override for MediaWiki

Tab override is now available for MediaWiki as well as WordPress: Tab Override @ MediaWiki

If you have a wiki and use it to post code Tab Override is definitely something to try out. You can see it in action at ErrorDatabase.

Resurrecting a Laptop for Development

I have an old single core laptop that doesn’t get a whole lot of use anymore, partially because it is dated (purchased in 2006) and partially I’ve never really adapted to using a laptop as a general purpose computer. Increasingly, however, I find myself in need of a laptop either when I want to get some work done when I’m away from home, or when I need to take my work with me. This being the case I decided to re-purpose my old laptop as a dedicated development machine.

I could have just put a fresh copy of Windows XP on it and gone from there, but given the circumstances that might not have been the best route. All I needed to run was apache, MySQL, PHP, subversion, and something to write code in. Clearly something more lightweight than Windows could accomplish this. In addition to this I wanted something that would mirror my production server, which is running ubuntu. I ended up installing lubuntu, a lightweight distribution based on ubuntu (if you plan on trying lubuntu bear in mind that it is still in beta). Other than some very minor bugs, lubuntu seems to be perfect for my needs: I could configure it to be almost identical to my production server, it is easy on resources (even on my ancient laptop), and I immediately noticed a big improvement with regard to battery life.