Mathew Davies home

What I've learned in the past year while running a website.

It’s been one year since my little hobby project Nolimits-Exchange went online. I’ve learned a lot over that year and I’d like to share some of what I’ve learned with you.

Advertising

Adsense was very poorly suited to the content of my website. I had a lot of Public Service Ads which although nice, don’t make any money. It was not worth annoying my users for the sake of 30 dollars a year.

We’re currently experimenting with another company. I’d love to say who, but that would be a breach of contract.

Backups

I’ve always backed up data with Amazon S3 via Duplicity; It’s cheap enough and works well, but I came across something better. I switched to an alternative called tarsnap.

The reasons:

  1. Write only encryption keys: I can be sure my backups wont be destroyed when the server is compromised.
  2. Pay as you go: This avoids any nasty surprises that could occur in my Amazon invoice.
  3. It has a similarity to tar, hence the name. It makes writing backup scripts easier.

It’s slightly more expensive at $0.30/GB-month versus Amazon’s $0.15/GB-month.

Community

I’ve had to ban a few members and one thing to look out for is suicide threats. I made the the assumption it was an empty threat and didn’t do anything about it. Don’t make that mistake and report the incident to the local police department.

Source: How do you handle suicide threats.

You should handle it just like any other threat to someone’s life. A person threatening suicide, or to kill someone else, is still threatening to kill someone. The only sensible thing to do is try and report it.

Beyond that it’s been a lot of fun meeting up with the community in real life.

I had a lot of help from Community Spark when starting. It features a lot of advice about choosing your staff, kick-starting your community, banning members, etc …

Development

The amount of improvement I’ve seen in my programming is a reminder that I’m not progressing as slowly as I’d thought. Take this example:

Original code: The XML is a string ($this->output) that was concatenated at various points.

<?php defined('SYSPATH') OR die('No direct access allowed.');

class Sitemap_Driver
{
	// XML header
	const header = '<?xml version="1.0" encoding="UTF-8"?>';

	// XML output
	protected $output = '';

	// Change frequency
	protected $changefreq = array('always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never');

	public function __construct()
	{
		$this->output = self::header.PHP_EOL;
	}
}

1 year later: I’m using the DOMDocument class which offers formatting, syntax checking and an easier API to work with.

<?php defined('SYSPATH') or die('No direct script access.');

class Kohana_Sitemap
{
	/**
	 * @var DOMDocument
	 */
	protected $_xml;

	/**
	 * @var DOMElement
	 */
	protected $_root;

	/**
	 * Setup the XML document
	 */
	public function __construct()
	{
		// XML document
		$this->_xml = new DOMDocument('1.0', Kohana::$charset);

		// Attributes
		$this->_xml->formatOutput = TRUE;

		// Root element
		$this->_root = $this->_xml->createElement('urlset');

		// Append to XML document
		$this->_xml->appendChild($this->_root);
	}

So take a look at your old code and be proud that you’re improving.

Deployment

When you have a busy website, you realise how important it is to keep the downtime to a minimum when pushing an update. The horror of FTP’ing a tarball to a server, then unpacking it only to find it didn’t work is a crap feeling (at best). This is why I learnt about version control, proper website deployment and database migrations.

I now use:

Downtime is no longer than 10 seconds and if I ever need to, can revert to an earlier state. I know very few developers that know all three, how are you surviving without migrations?

If you’d like to learn more about Capistrano, then my article PHP Deployment might be helpful to you.

Discuss on Reddit or Hacker News.