Testing the Yii Framework


First, download the Yii Framework to somewhere sensible. I prefer to use subversion to check out the code:

svn co http://yii.googlecode.com/svn/branches/1.0 /usr/share/php/Yii

This will take a few minutes. Once it’s done, you can use the Yii Command Runner (yiic) to set up your web application:

/usr/share/php/Yii/framework/yiic webapp /var/www/html/appname

If everything went well, you should be able to access your web app with:


You should see a screen like the following one:



Set up the config script to be able to connect to your database.


Uncomment the DB section, and add in your database connection details:


Developing with Subversion, Unfuddle and OSX

Today I’m going to be helping one of our investment companies, ByteWire set themselves up with a subversion based development environment for their Street Crime game. They will use a straight forward workflow whereby they will develop and test their code locally on their iMacs, commit working code to a subversion repository, and then check out code the live site when they are happy with it.


We’re going to be using Unfuddle to provide subversion hosting, project management and bug tracking.

  • Create a free unfuddle account, e.g. Bytewire
  • Set up your first project e.g. Street Crime
  • Create a repository: http://bytewire.unfuddle.com/svn/bytewire_streetcrime/


Set-up a local test domain on OS X

  • Add it to the hosts file
printf "\tstreetcrime\n" | sudo tee -a /etc/hosts
  • This should now be accessible via http://streetcrime/


MAMP is an excellent bundle of Apache, MySQL and PHP for use on Macs. These tools do come pre-installed with Leopard by default, but php in particular is missing a fair few modules which you can only really add by re-compiling – MAMP makes it a lot easier. It installs new versions of PHP, MySQL and Apache alongside the default versions (on different ports), so that both can be run at the same time.

    • Create a folder where the site code will be placed, e.g. /Applications/MAMP/htdocs/streetcrime/http/
    • Open up /Applications/MAMP/conf/apache/httpd.conf with a text editor.
    • Uncomment the NameVirtualHost line, and add a couple of news lines to define the new virtual host. It should look like:
NameVirtualHost *

<VirtualHost *>
DocumentRoot /Applications/MAMP/htdocs/
ServerName localhost

<VirtualHost *>
DocumentRoot /Applications/MAMP/htdocs/streetcrime/http/
ServerName streetcrime
  • Restart MAMP through the MAMP control applet or widget. You should then be able to access the site at http://streetcrime:8888/


  • Make the trunk folder inside the repository where your site code will initially be kept.
svn -m '' mkdir http://bytewire.unfuddle.com/svn/bytewire_streetcrime/trunk/
  • Check out the trunk to your project top level folder
svn co http://bytewire.unfuddle.com/svn/bytewire_streetcrime/trunk/ /sites/street-crime.com/
  • Check through the folder structure and look for anything that should be excluded:
du -h --max-depth=1 /sites/street-crime.com/http/
  • Edit the svn:ignore property
svn add /sites/street-crime.com/http/
svn propedit svn:ignore /sites/street-crime.com/http/
  • List the files & folders that you want to ignore, and then save and quit.
  • Add the remaining files and commit (excluding uploads etc with svn:ignore)
svn add --force /sites/street-crime.com/http/
svn commit -m 'Importing main files'


  • Change directory to the folder you set up locally for development.
cd /Applications/MAMP/htdocs/streetcrime/
rmdir http
svn co http://bytewire.unfuddle.com/svn/bytewire_streetcrime/trunk/ .


  • Visit http://streetcrime:8888/ – it showed a blank page for me. That would suggest error reporting is off, so enable in /Applications/MAMP/conf/php5/php.ini

WAMP SMTP Server – Send outgoing emails

If you are running WAMP and you want to be able to send outgoing e-mails via PHP’s mail function, then you will need to edit the php.ini file and change

SMTP = localhost


SMTP = smtp.yourisp.com

Replacing smtp.yourisp.com with the address of your ISP’s SMTP server, e.g. smtp.ntlworld.com. The php.ini is in the bin directory of the active Apache, which will be something like:


However, if you are using Zend Mail and you get an error along the lines of

Warning: mail() [function.mail]: SMTP server response: 501 <"Bill Gates" <[email protected]>>: "@" or "." expected after """"

Then you should probably bypass PHP’s mail functions altogether, and connect directly to the SMTP server from Zend Mail:

require_once 'Zend/Mail/Transport/Smtp.php';
$tr = new Zend_Mail_Transport_Smtp('mail.example.com');

So to send a mail from WAMP using Zend Framework’s Mail functions, you would use the following:

require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';

$tr = new Zend_Mail_Transport_Smtp('mail.example.com');

$mail = new Zend_Mail();
$mail->setFrom('[email protected]', 'Bill Gates');
$mail->addTo($email, $name);

Effective 2009-2010 Tax Rates

If you factor Employee’s and Employer’s National Insurance Contributions into the total deductions made by the tax man, then most people pay closer to 30% tax than the headline basic rate of 20%.

The following graph shows the total % tax paid by an employer + employee for a given nominal gross salary. This includes income tax and employee / employer national insurance.

MySQL one database versus multiple databases

When designing an application – should you put each customer in a separate database or keep them all in one large central database?

When it came to start work on our new Clear Books accounting software last year, we had to make a fundamental database design choice between using a single database for all clients, or having a separate database for each one.

Since there was going to be a fairly large amount of data for each client, we decided to go for the latter, and one year on – I am very happy with our decision.


  • Easier to balance load. Since each client is in a separate database, it is relatively easy to move them between database servers.
  • Faster. One client’s tables being locked won’t affect another clients. Indexes are smaller. If MySQL has to do a row scan (let’s hope it doesn’t!), it’ll be faster.
  • MyISAM rsync backups will be faster.
  • Easier to clone a clients database for testing purposes (just simply copy the whole db, no need to write a special script to extract their data).


  • Upgrading the database is more complicated, as you have to add new fields to each client database, rather than just once globally. If you are successful you could be dealing with thousands of databases, and so an upgrade script is definitely needed. However, this is also a blessing in disguise as it allows you to test upgrades on a small set of databases before rolling them out generally.
  • More complicated to implement in general.

I think the ultimate decision would come down to how much data your store for each client. If it’s a fair amount, then I think separate databases is worth the extra development effort.