Development

Building scalable web applications

Scalability is a desirable property of a system, a network, or a process, which indicates its ability to either handle growing amounts of work in a graceful manner or to be readily enlarged. (Wikipedia)

In order to achieve good scalability an application has to be designed with scalability in mind. Every application requires its own level of scalability and performance, and this should ideally be addressed during functional and technical design specification.

During this design phase there are a number of things to consider, – especially performance. Higher performance generally means more requests per second and less intensive operations; good caching is vital (think Smarty, ZendPlatform, memcached etc)

Where possible try to build software that is ‘loosely coupled’, – that way if it is required in the future it will be possible to serve different components from different servers. Often application bottlenecks occur in a small part of the application so with loosely coupled software it is easier to relocate that component to dedicated hardware.

Infrastructure architecture must support the application architecture. PHP web server clusters require a solution for sharing sessions between servers. These servers can have their own local cache or they could use a shared caching mechanism. Building on a SOA architecture can help spread load across multiple servers.

Designing a database includes thinking about scalability and performance. While replication is a good way to spread read queries across multiple servers it doesn’t help when you have lots of writes. Data partitioning is a valuable consideration; for example each group of database servers can serve part of your database. This allows you to spread writes to different groups of servers, however obviously adds to the complexity of partitioning and fetching data.

During the development process ensure that you develop with a database that reflects the real thing. Try to populate your database with content before you start developing as a database with just a couple of rows behaves different to one with millions of rows.

Building scalable web applications Read More »

Scheduling mySQL backups

I’m sure there is no need to explain the virtues of regular backups. Below are three steps to peace of mind

1) Configure a backup directory on the server

mkdir /var/lib/backupfolder
cd /var/lib/backupfolder

2) Make a backup script

vi mysqlbackup.sh

#!/bin/sh
# MySQL server username goes here
USERNAME="username"
# MySQL server password goes here
PASSWORD="password"
# List of DBNAMES for Backup
DBNAME="dbname"
#date timestamp used in the log
DATE=`/bin/date +%Y-%m-%d_%Hh%Mm`
# format the output file
OUTDIR="/var/lib/backupfolder/"
OUTFILE="ip_bindass".$DATE."sql.gz"
#working directory
DIR="/var/lib/backupfolder/"
#cd $DIR
# Do the MySQL Backup
/usr/bin/mysqldump --database $DBNAME --opt --single-transaction -u$USERNAME -p$PASSWORD | /usr/bin/gzip -9 > $OUTDIR$OUTFILE

Dont forget to change permissions

chmod +x mysqlbackup.sh

3) Schedule the backup in crontab

crontab -e

Add something along the lines of:

30 23 * * * /var/lib/backupfolder/mysqlbackup.sh

To backup at 11:30PM every day. Just as important as to backup up is to test restores; – it’s no good having backups and feeling at ease if you cant recover in the event of catastrophe!

Scheduling mySQL backups Read More »

Is PHP Agile?

A client recently asked if PHP was an Agile programming language, and during the (rather lengthy) explanation a few principles worth exploring were covered:

In the context of software development Agile is really no more than a set of principles and values. At a meeting in February 2001 people who were then developing software differently to traditional processes drew up a manifesto; they formalised practices favouring constant feedback and change, flat hierachy, and delivered early and often.

PHP is generally considered a lightweight language, – often it is used because it can get things done quicker than with other languages. A language is never agile because it does not generally define the processes used when developing with it. However it can have qualities that can make its development quicker; PHP is light, interpreted, and it is simple. Unfortunately these reasons have also attracted people unconcerned with best practices in order to ‘just get their sites up and running’

Agile doesnt mean doing the job quickly, – dont expect to finish the project earlier, but you will deliver earlier. A part of the system that is testable, usable, and something that adds value. From the feedback the team and customer will decide what will be delivered next. The iterations are closer together than other approaches and in order to deliver quickly you will only deliver what you need.

As far as web application development is concerned, being an interpreted, lightweight, embeddable, simple language, with fairly reasonable object oriented support, PHP is in a fairly unique position to fulfill the needs of agile development teams. The elements are available, but of course it is up to the enterprises to take the step and use what is there for setting up their own agile development environment.

Is PHP Agile? Read More »

Obfuscating email with PHP

This is a function to protect email addresses on your website from bots or spiders that harvest email addresses for spam purposes; it uses a substitution cipher generating a unique key for every page load.
PHP encrypts your email address and generates javascript to decrypt it because most bots and spiders can’t execute javascript. A visitor of your web page will not notice this as long as they have javascript enabled, otherwise they will see “[javascript protected email address]”

As the script contains quite a lot of special characters, a downloadable version is available here

Usage
echo hide_email(‘test@test.com’);

Further reading
Ross Killen’s implementation here
Methods to hide email addresses in page source here

Obfuscating email with PHP Read More »

Mono Develop


Version 2.2 just released!

MonoDevelop is an IDE primarily designed for C# and other .NET languages. MonoDevelop enables developers to quickly write desktop and ASP.NET Web applications on Linux, Windows and Mac OSX. MonoDevelop makes it easy for developers to port .NET applications created with Visual Studio to Linux and to maintain a single code base for all platforms.

MonoDevelop is a free GNOME IDE primarily designed for C# and other .NET languages, although open to any kind of language. However, MonoDevelop hopes to be more than just an IDE: it intends to be an extensible platform upon which any kind of development tool can be built.

Get it here

Mono Develop Read More »

Pencil prototyping tool

Came across an interesting project today: Pencil. Pencil is a GUI prototyping and simple sketching plugin for Firefox (released under the GPL.) According to the website: The Pencil Project’s unique mission is to build a free and opensource tool for making diagrams and GUI prototyping that everyone can use.

Features include:

  • Built-in stencils for diagraming and prototyping
  • Multi-page documents with background page
  • On-screen text editing with rich-text support
  • PNG rasterizing
  • Undo/redo support
  • User-defined stencils
  • Standard drawing operations: alignment, z-ordering, scaling, rotation
  • Cross-platform

As a free option it seems to compete quite well with the likes of Visio, Omnigraffle, Axure, iRise etc, – especially considering its cost. Whilst it lacks some of the more advanced features of its competitors it seems to have great potential, even at version 1.1.

Have a look at it here

Pencil prototyping tool Read More »