Lightweight Continuous Integration for PHP
This post describes a simple, lightweight strategy for implementing Continuous Integration on PHP-based software projects. This approach happens to use Subversion for version control, PHPUnit for unit testing, and Phing to automate the processes involved, but hopefully the principles are generally applicable.
The post won't strive to be exhaustive or encyclopaedic, rather it will present a simple proof-of-concept and a brief overview of the tools that are available to PHP developers. But first some background...
Read more »Command-Line Subversion Tutorial, Part 3: Subversion Properties
In Part 1 of this series we looked at the basics of command-line Subversion, and Part 2 covered importing, branching and merging. In this third part I'd like to introduce a useful and very powerful Subversion feature, which isn't always terribly well understood by developers: that of Subversion Properties.
Read more »Command-Line Subversion Tutorial, Part 2: Importing, Branching and Merging
In Command-Line Subversion Tutorial, Part 1: The Basics, I covered many of the more common svn commands, and hopefully illustrated a typical SVN workflow.
This time around I'd like to tackle some of the commands involved in managing a project within a Subversion repository, specifically those that you'll need in order to import a project to a repository, and to branch and merge a project's codebase.
Read more »A First Look at the New WURFL API for PHP
About a month ago, the New WURFL API for PHP was officially released. While the code had been available in one form or another for some time, the official release coincided nicely with the early stages of a new project at work, so it seemed like an appropriate time to have a look at the API and see if it was something we wanted to use.
By way of a refresher, WURFL is a "Device Description Repository" - a huge open-source XML-based database of information regarding mobile handsets and their capabilities. I've discussed WURFL in the past, for example here. Prior to this release, the only practical method of querying WURFL in real time from PHP was via a library named Tera-WURFL, which I blogged about here. In fact, both WURFL and Tera-WURFL were covered in an article I wrote for php|architect magazine last year.
We've generally been very happy with Tera-WURFL, but it's always worth considering one's options, so what follows is an overview of my experiences with, and first impressions of the New WURFL API.
Read more »Unit Testing Code which Consumes SOAP Services
One of the trickiest aspects of unit testing or Test Driving an application's code is testing those parts of the system which depend on an external system, such as a database or a SOAP service.
In this post I'll outline an approach to testing a class which happens to communicate with a third-party SOAP service using PHP's built-in SoapClient
class. Hopefully, the principles involved will be applicable to the more general case of testing code which relies on an external system.
Command-Line Subversion Tutorial, Part 1: The Basics
I'm constantly surprised by how many experienced developers are completely unfamiliar with using version control - such as Subversion or CVS - from the command line, instead preferring to rely on graphical clients such as TortoiseSVN.
Don't get me wrong - Tortoise has its uses - but I strongly recommend that any professional developer familiarise themselves with command-line version control. It's simpler, quicker and a thousand times more powerful.
In this post I'd like to help those developers out by covering the basics of command-line Subversion usage, via the svn command. I've optimistically named the post "Part 1" in the hope that I'll manage a follow-up post one day, covering more advanced issues such as merging and resolving conflicts. For now though, let's have a look at the basics.
Read more »Adding a Doctype Declaration to a DOMDocument in PHP
I've recently been spending quite a lot of time with PHP's DOM extension, which is extremely useful for both generating and parsing XML.
In this particular case, I'm generating XML, and it's imperative that the XML markup which the code is generating should contain a Doctype declaration (DTD). It isn't hard to do that using DOM, but it did take a little bit of hunting around in the manual and online, so here's a quick overview of how to add a Doctype declaration to a DOMDocument.
Read more »PHP Closing Tags Considered Harmful
It may be obvious to some, but this is a mistake I still see being made a lot, and I think it's high time we got over it.
Stop using PHP closing tags. It really is that simple, and here's why.
Read more »Syntax Highlighting with GeSHi
On this very site, I've recently started using GeSHi, to implement the rather nifty code syntax highlighting you see in posts like this and this.
I had previously been using PHP's built in highlight_string()
function, but that function is only of use for highlighting PHP code! As I often seem to need to highlight other languages, it was time to turn to GeSHi.
Since I did, a couple of people have asked about ease of use, implementation and so forth, so this post is my attempt at answering those questions.
Read more »More Mono: mod_mono and Apache
In Getting Started with Mono on Linux I mentioned that my next plan was to get Mono integrated with Apache HTTPD by way of mod_mono.
This turned out to be a bit of a wrestling match. The process itself is remarkably simple, but the poor - or at least outdated - documentation combined with a few minor teething problems made it all much harder than it could have been.
Read more »Getting Started with Mono on Linux
I've recently had cause to look into various strategies for integrating PHP and .NET (on which subject, pointers will be most welcome), which led to a brief investigation of Mono. For the uninitiated, Mono is a "a cross platform, open source .NET development framework". In short, it allows you to compile and run .NET code on a Linux server.
Mono is fairly straightforward to install, although the process isn't terribly well documented, so I figured I'd run through the steps here in case it might help somebody. As a bonus, we'll have a look at something called XSP once we're done.
Read more »Copyright/License Comment Blocks Considered Harmful
Rant alert. You know what really grinds my gears?
It's those epically long license/copyright notice comment blocks with which some developers, particularly those behind open source PHP projects, insist on prepending source code files.
You've all seen this kind of thing. I'm using Wall4PHP to illustrate my point, but they're by no means the only offenders.
Read more »"Working with Zend Platform" Published
Another month must be nearly upon us, and with it comes a spanking new issue of php|architect magazine.
I'm pleased to mention that my article all about Zend Platform is featured, along with lots of other goodness.
I found Ivo's introduction to ATK particularly interesting, and it's a tool I'll be pressing into service before long.
I have a couple of ideas for future articles, but they may take a backseat to my studies for the time being.
Read more »August '08 Issue of php|architect Magazine Out Now
I've just spotted that the August issue of php|architect magazine is now available for download, and it's a top quality issue as always, with articles on writing Wordpress plugins and Facebook apps, an introduction to Adobe's Flex, and finally James Cauwelier's case study of scaling out an e-Commerce site to support a million products.
I'm really pleased to have been involved with the technical editing of this issue, and there's a certain swelling of pride in spotting one's name in the editorial credits (alongside Richard Harrison, I note; Richard being the man responsible for putting ElePHPants on the desks of most of London's PHP developers).
Read more »Presentations on Slideshare
I've been doing a bit of presenting at work recently, which has meant getting my head around making up slides (using OpenOffice, of course). It all feels a little bit Dilbert, in a way.
Anyway, there's nothing particularly groundbreaking or PlayPhone-specific about these slides, so I've put them up on Slideshare in case anyone fancies a look.
Read more »"PHP Tools for Mobile Web Development" Published
This is just a quick heads up to say that my article, "PHP Tools for Mobile Web Development" has today been published, and is currently gracing the cover of July's php|architect magazine.
Of course, I jinxed things a little by blogging that it would be published in June, but never mind, we got there.
Big thanks must go to Ciaran for giving the initial draft the once over (on a related note, check out Ciaran's post about web development for the iPhone). Thanks also to my occasional colleague Gerard for clueing me in to the fact that the damn thing had been published.
For what it's worth, php|architect is recommended reading even when I'm not in it, so get yourself over there and get subscribed!
Ok...now to crack on with that second article...
Read more »Mobilising a Website, Part 2: Strategies
In Mobilising a Website, Part 1: The Problem I noted that this site is practically unusable when viewed using the browser on a mobile handset, and that I'd like to do something about that.
This time around, I'd like to size up some of the approaches and strategies that developers can take in order to make an existing website mobile-friendly.
Read more »Response to "10 Things a Developer Should Never Ignore"
Earlier this week, I stumbled across Bill Stronge's recent 10 Things a Developer Should Never Ignore over on TechRepublic. It's recommended reading, as it's an interesting piece, filled with useful advice for developers, especially those just getting started in their programming career.
Still, a couple of the points jarred with me a little, and there were a couple which I felt could have been taken further. So here's my response to Bill's 10 Things.
Read more »Benchmarking Zend Download Server
Recently I've started looking into ways that the PHP dev team in which I work can make better use of our Zend Platform installation.
For that reason, the recent Ibuildings/Zend seminar in London on the subject of "Enterprise PHP" was well timed, as it included a pretty detailed run through of a lot of what Platform has to offer.
One feature which really struck me as having the potential to bring performance benefits to one of our systems was the Zend Download Server. Back at the office, I looked into the feature, and ran a few benchmarks. Oddly though, the results don't seem to flatter Zend Download Server.
Read more »Fighting Spam and Digitising Books with reCAPTCHA
When I added a comment form to this blog, I wondered how long it would be before I started getting comment spam. Then I wondered if I was flattering myself to think that spam bots would even be interested in my site.
So it's with mixed emotions that I have to admit that right now the number of spam comments I'm receiving is outstripping the number of genuine comments by a ratio of about 10:1.
The time has come to add a CAPTCHA to the comment form.
Read more »Mobilising a Website, Part 1: The Problem
It hasn't escaped my notice that if one happens to visit Pointbeing.net - this very site - using the browser on a mobile phone, the experience is more than a little painful. In fact, more often than not, the site is simply unusable.
The reason for this is that the site does not adapt itself in any way to the smaller screens, slower connection speeds, and idiosyncratic navigation methods found in mobile devices.
In my defence, this is not unusual right now: many, many sites are in the same position (have you ever tried to visit LinkedIn on a mobile?). However, given my faith in the future of the mobile web, and also given what I do for a living [1], this is something of an embarassment. The time has come to mobilise Pointbeing.net.
Read more »Zend_Search_Lucene Quick Start
I recently had a spontaneous urge to add a search form to my weblog - this one you're reading right now - and it seemed like a good opportunity to have a look at Zend_Search_Lucene.
I'm really impressed with the simplicity and power of the module. Sadly the documentation, whilst extensive, isn't particularly clear - so here's a quick overview of getting Zend_Search_Lucene up and running.
Read more »An Introduction to Fire Eagle
A definite highlight of Over the Air 2008 was London-based Yahoo Steve Marshall's introduction to Fire Eagle. For those not in the loop (which, to be fair, is most people: Fire Eagle is currently only open to a limited number of invited developers) Fire Eagle is Yahoo!'s brand new API for location-based services.
Read more »PHPTuring
A few years ago, as an exercise in Test-Driven Development, I wrote a Turing machine simulator in PHP and imaginatively named it PHPTuring.
I had completely forgotten about it until today, when I dug it out for another look. Truth be told, I still haven't seen a Turing machine done any better in PHP, and apart from a few syntactical niceties (removing closing PHP tags as per the Zend way, neatening up the PHPDoc blocks) I'm actually pretty comfortable with the code.
Using it is a breeze. It reads pipe-separated tapes and newline plus pipe-separated instruction sets like so:
<?php
$prog = '0|1|1|R|0\n0||1|R|1\n1|1|1|R|1\n1|||L|2\n2|1|||stop';
$tape = '1|1|1|1|1|1||1|1|1|1|1|1|1|1';
$machine = new Machine();
$compiler = new SimpleCompiler();
$parser = new SimpleTapeParser();
$debugger = new SimpleDebugger();
$debugger->watch($machine);
header('Content-type: text/plain');
$machine->run($compiler->compile($prog),
$parser->parse($tape));
It should work with other formats, so long as someone writes parsers for them. Similarly, the debugger is just an Observer that dumps the state and tape to the screen at each step, but it could easily do something more subtle some day.
The code ships with full tests, and is available for download on PHPTuring's Sourceforge download page.
So why am I banging on about it here? I don't know. Maybe just because I like it, because it was the first afternoon's coding that really got me test-infected, and because I'd be interested in any feedback.
Read more »MySQL versus PostgreSQL: Adding a 'Last Modified Time' Column to a Table
This is the second post here detailing my ongoing adventures with PostgreSQL. This time I had a requirement to add a "timestamp" column to a table. The point of this being to allow us to track the "last modified" time of a row, without requiring that the application code manage the timestamp itself.
There's a lot of reasons why you might wish to do this. In this case it was to simplify syncing the data into a data warehouse. More specifically, to allow the DBA to easily identify rows which have changed since the last import.
Having done this a couple of times in MySQL, I assumed that the process would be straightforward. I should know better by now!
Read more »An Introduction to Tera-WURFL
I recently added a post about Wurfl, a comprehensive open-source XML database of mobile device capabilities. I noted that actually querying Wurfl in a performant manner:
is going to be a non-trivial task, and is perhaps a topic for a further article.
Well, I guess this is that article. It's time to have a look at Tera-WURFL, which is perhaps the most popular tool for querying Wurfl programmatically - from PHP, at least.
Read more »MySQL versus PostgreSQL: Adding an Auto-Increment Column to a Table
The bulk of my database experience (almost eight years now) has been with the popular open-source MySQL database management system. MySQL has progressed significantly over the years, and has grown into a remarkable product. It finally has all the must-have features such as views, stored procs and referential integrity, coupled with the blistering performance for which MySQL has always been known. In short, it rocks.
But I digress. I've recently been having to get to grips with PostgreSQL (an old version of course - 7.1 or so - just to make life really interesting). It's largely intuitive, but there are quirks around most corners. This is my favourite so far: I recently needed to add an auto-incrementing integer "id" column to a table.
Read more »Managing Mobile and Non-mobile Versions of a Site Using Tera-WURFL and Zend Framework
This is a quick proof-of-concept I put together after a discussion on how to deal with running a mobile site and a 'full' web site on the same hostname in a sane way, and to transparently route user agents to the appropriate site.
Read more »JsUnit
Just a quick post to mention that, yes, my commitment to TDD show no signs of abating, especially in the face of the various unfamiliar technologies with which I've been working recently.
Today I came across JsUnit. Which may be old news to many, but I don't stray into JavaScript territory very often, and when I do, I'm usually quite frightened!
And how do developers reduce fear? Yup, we write some tests.
JsUnit has a nice UI, has maybe a 5 minute install/learning curve for anyone familiar with xUnits and just works. The only downsides I've found so far are that i) it doesn't work with my adored Opera and ii) some of the debugging messages are written in the sort of cryptic, broken English that suggests that the contributions of a native speaker might be welcome here.
Anyway, long story short, it's nice to know that even in the dark, dark world of client-side scripting, the gospel is spreading.
Read more »Try Ruby!
I'm intrigued, perhaps even impressed by Why's Try Ruby!, an interactive, in-browser Ruby tutorial. It really is quite a fascinating collision of technologies.
It's almost painfully Web 2.0 - I'm pretty sure most of the buzzwords are there - Ruby, Ajax, that sort of thing. All sat on top of the ubiquitous Json and Prototype libraries.
It's a neat idea, and a useful tool in learning what is a very interesting programming language, but it displays something which is has become alarmingly common in the Web 2.0 landgrab - a complete disregard for the usability conventions and metaphors that have made the web such a success in the first place. Want to bookmark a particularly useful page of the tutorial? Oops, no, sorry - you can't do that, best start again. Want to hit your 'back' button and run over that tricky last section again? No such luck.
I don't want to sound like a miserable old bugger (well, maybe just a little), but I'm starting to fear for the future of HTTP. I'm nostalgic for TBL's original design.
Still, everyone has the sense that we're in a fascinating and exciting phase in the Web's development - even I can't deny that. It will be interesting to see how this pans out.
Read more »URL File Extensions Considered Harmful
A recent conversation with a colleague reminded me of just how much I hate seeing programming language file extensions in URLs. You know - .php, .asp, .cfm and the like. There are several reasons why we avoid them like the plague.
Read more »