Testing the Yii Framework

Installing

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:

http://hostname/appname/

You should see a screen like the following one:

yii-default-screen

Configuring

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

/var/www/html/webapp/protected/config/main.php

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

'db'=>array(
			'connectionString'=>'mysql:host=localhost;dbname=http_auth',
			'username'=>'root',
			'password'=>'d2x@1A1!aa!a!',
			'emulatePrepare'=>true
		),

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.

UNFUDDLE

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/

LOCAL DOMAIN ON OSX

Set-up a local test domain on OS X

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

MAMP

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>

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

INITIAL COMMIT OF CODE

  • 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.
PSD
gangster-game-forum
gangster-game-wiki
gangster-game-blog
logs
uploads
  • 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'

CHECKING OUT CODE TO THE OSX DEVELOPMENT WORKSTATION

  • 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/ .

TESTING THE SITE

  • 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

to

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:

c:\wamp\bin\apache\apache2.2.8\bin

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');
Zend_Mail::setDefaultTransport($tr);

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');
Zend_Mail::setDefaultTransport($tr);

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

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.

Advantages

  • 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).

Disadvantages

  • 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.

Unemployment versus House Prices 1975-2008

The following graph shows the quarterly unemployment rate compared to real house prices. House prices have been adjusted for inflation and are given in 2009 Q1 prices.

unemployment-house-prices-1975-2008

Sources

Learning Fonica PABX and FreePBX

I’ve been testing out a few free PBX distributions, and the most recent one I’ve tried is called Fonica PABX. It’s basically a bundle of Centos, Asterisk, FreePBX, and some other asterisk modules that are wrapped together with a nice installer system.

Step 1 – Install Fonica PABX

  • Download the latest ISO and burn it to a CD
  • Follow the instructions on the Fonica PABX wiki.
  • Make sure you change all the default passwords as described in the instructions, otherwise your box will be open to the world.

Step 2 – Set up some extensions with FreePBX

  • Browse to FreePBX > Basic > Extensions
  • Add a generic sip device, specifying the user extension (e.g. 0001) and a secret (password)
  • You may also wish to enable call recording, and voice mail – if so, specify a voicemail pin.

Step 3 – Configure FreePBX to allow Inbound and Outbound calls

In this example we are going to set up a trunk to Magrathea Telecom to allow inbound / outbound calls via IAX2.

  • Browse to FreePBX > Basic > Trunks
  • Add an IAX2 Trunk.
  • For the outgoing settings, give the trunk a name such as “magrathea-out”, then specify the hostname (iax3.magrathea-telecom.co.uk) and your username / password. Magrathea or your VOIP service provide will have given you these details.
  • For the incoming settings, the user context (username) and secret (password) are the authentication details that the VOIP provider will use when connecting to you. In Magrathea’s case we can set these to anything we want, we then notify magrathea of them through an API call. E.g. username:[email protected]

After the trunk is setup, you must define both an outbound and inbound route. For the outbound route:

  • Browse to FreePBX > Basic > Outbound Routes
  • Give the route a name, e.g. default
  • Specify the dialplan pattern, e.g. XXXXXXXXXXX would match any 11 digit number
  • Specify the outgoing trunk to use e.g. magrathea-out (or the name you used when setting it up).

For the inbound route:

  • Browse to FreePBX > Inbound Call Control > Inbound Routes
  • Give the route a description (e.g. default) and a destination (e.g. an extension, voicemail, queue or ring group). You can leave the DID number blank if you want this to be a default route, but fill it out  if you want to match a specific number. Magrathea send the DID numbers in the full international format, e.g. 448448160054.

Step 4 – Install additional FreePBX modules such as Queues and Ring Groups

  • Browse to FreePBX > Admin > Module Admin
  • Click “check for updates online”
  • You should then see a list of modules. Click on the modules you would like to install, and then select the “download and install” action.
  • Once you’ve chosen all the modules you want, click the “process” button in the bottom right hand corner of the page.

Other things I plan to do:

  • Set up queues and / or ring groups with their own voicemail (how can queue members access it?)
  • Set up a phone directory to
    • Automatically look up known caller ID from a database, and append to CID on inbound calls.
    • Allow directory lookup from Snom phone itself.
  • Get auto-provisioning working, to automatically assign extensions to our snoms.
  • Work out how to set up patterns for inbound calls, so that 0844 816 XXXX goes to extension XXXX.
  • Port our existing geographic numbers from BT to Magrathea and assign to extensions.
  • Set up system to fall back to analogue lines if VOIP not working, and also to route 999 / operator calls out over PSTN.
  • Is it secure to allow “anonymous inbound sip calls” from the FreePBX > Basic > General Settings menu?

Trixbox blue screen after probing video card

I was experiencing an error during an installation of Trixbox 2.6.2.2 whereby it would lock up with a blue screen after the keyboard language selection / probing video card steps. Initially I thought it was a faulty CD, but after burning 3 copies with 2 computers, I would get the same problem every time.

This thread had some more info, but in the end I fixed it by disabling the machines secondary hard drive.

Replacing benefits with a Basic Income

For a while now I have been thinking that there must be a better way to re-distribute income in our society. The current welfare system is hugely inefficient and complicated with all the means testing and civil servants needed to administer it.

Our system is also full of perverse incentives, whereby it encourages people NOT to work. If you are unemployed and receiving benefits, then you risk losing them by going back to work, and unless your new job pays well above minimum wage, you might not be any better off!

Wouldn’t it be better to provide everyone with a minimum amount of income (funded through taxation) that was not in any way mean’s tested? This would remove a huge amount bureaucracy and encourage unemployed people to get a job without the fear that they would lose their existing income.

Basic Income

The idea is known as a Basic Income – also referred to as a Citizen’s Income. It is similar to a Negative Income Tax and it works like this:

  • It is paid to individuals rather than households;
  • It is paid irrespective of any income from other sources;
  • It is paid without requiring the performance of any work or the willingness to accept a job if offered.

I think that this basic income could then be combined with universal public services, free to the end user. So every citizen would receive a fixed basic income plus certain guaranteed minimum entitlements, such as health care, education, shelter and security.

The public and private sector would compete to provide schools, hospitals, and accommodation to satisfy the universal guarantees. The social housing should be modest to keep costs down and to encourage people to work if they want better.

In the 2008 Budget, we spent £169 billion on social protection – that’s almost £3000 for every citizen of the UK – £57 a week per person. The basic income could be stepped, so that children receive the lowest amount, working age adults would earn more, and pensioners would receive the most.

Advantages of the Basic Income System

  • Increased incentives and rewards for those who want to work.
  • Simpler, more efficient and easier to implement than the complicated means tested system we have now. Thus represents better value for citizens.
  • Minimum guaranteed income for all citizens

We should simplify the tax system at the same time, and scrap the complicated capital, corporation and income tax schemes with a single flat tax.