Version Parameters for Web Services

This is a mini series on points to consider when designing and building web services. So far there have been posts on error feedback for web services, auth mechanisms for web services and saving state in web services.

When designing a service API, there are lots of things you can do right, and plenty of pitfalls. Most of both of these are completely specific to the situation you are designing for but I have one tip that has helped me out in a number of scenarios: Include a version parameter with every method call.

This is invaluable, not just in development where you can increment when you change the API (which could be quite often!) but also in production. For example if you want to extend or alter an existing service, you can identify which version of the API the client thinks it is accessing and behave accordingly – either letting them know there’s a new version, or preserving previous behaviours. Its never ideal to change the API of an existing service but sometimes it makes more sense to do so, especially if its just to include an additional parameter or something else quite minor, but which does cause an API change.

When you publish your shiny new service which does everything you need (including the hoovering), it might seem a bit redundant to require a field which is always set to the string “1.0” … but in 18 months time, you’ll be patting yourself on the back.

Saving State in a Web Service

This is a mini series on points to consider when designing and building web services. So far there have been posts on error feedback for web services and auth mechanisms for web services.

Web services, by their very natures, are stateless, and this is no different to any other web application with a frontend. Its often helpful to keep track of the sequence of events something experiences. Similarly we might want to store the details a particular piece of data encounters on its lifetime in the system. When it was created, when it was changed, where in a given process it is up to, and so on.

A good example of this is a service I run for a few friends which accepts a URL, requests it and takes a screenshot, then turns that into a thumbnail and makes it available. There’s a few definite states in that sequence and its better to store which it is than try to guess from which fields have dates in or something. So the states are something like “new”, “error”, “in progress”, “ready” and “expired”. I can look at any of the jobs that come in, at any time, and know exactly where that item is up to.

When Things Go Wrong

It’s also pretty to have a strategy for failure. I already talked about giving users sensible feedback from a service, but the service also needs to keep track of what’s happening. There are decisions to make which depend entirely on the application under consideration but for example whether a failure is terminal, or whether the system should keep trying is quite an important thing to consider. Perhaps you just want to flag records that failed, so you can check on them later. Or you might want to retry – a set number of times? Or at decreasing intervals? An undesirable outcome would be to have the same record submitted every minute (or whatever) forever, so its worth planning to avoid this eventuality. Think also about the likely causes for failure – a split-second glitch or a likely human error which might take a day or two to be noticed and rectified?

Logging

Logging is something which is ideally of zero value. If nothing ever went wrong, you’d never care to look at an individual record and dig into its journey. However in the real world, we do need to be able to debug systems, sometimes under pressure. With logging there are a few different choices – whether to log to file or database, and whether to log continuously, or only at given times. Times when you might want to enable or increase logging are in development and when tracing a bug. However having some background amount of logging (and a way to stop the archives becoming too large) is recommended to keep track of who did what and when. Bear it in mind for a service just as you would for a web application.

Memcache Follow-Up Article on Techportal

Today techportal published a new article of mine on their site – New Memcached Extension for PHP. Its a sequel to the article I wrote for them earlier in the year entitled Getting Started with Memcache. At the same time I wrote that first article, Andrei Zmievski released a new extension for PHP to make use of the functionality in the libmemcached library – so I wrote the new article to give some information about it.

Fixing Broken Serendipity Category

I migrated this blog to serendipity almost two years ago, and there have been a few things about it which have always driven me a bit mad. Many of these improved when I upgraded to version 1.4.1 of s9y but a few have persisted, including having two of my sidebar categories not display correctly. Where most of the categories behave as expected, two of of them just didn’t apply any filter at all and all my posts were visible on these pages.

I finally sat down today to diagnose the problem and discovered I was missing a record from the serendipity_permalinks table which was stopping s9y from being able to look up the id of the category. It was my craft category which is id 7 – all I had to do was run the following against mysql:

insert into serendipity_permalinks set permalink = "category/craft", entry_id=7, type="category";

So now my craft category works fine. If anyone knows how to stop my feeds from showing old articles as new when I edit them but don’t update the publication date, I’d be grateful! A bunch of imported posts are still missing their images, would be nice to be able to fix these without polluting my feed.

New Patio and Garden Gate

There haven’t been any house updates for a while – because I haven’t been here so haven’t done anything! However we did realise earlier this year that we were never going to find the time to lay our own patio, we’ve been in the house two years now (can I get a little “yay!” for that?) and still nowhere to sit outside, so I found a local garder who could come and do it, he even has a website so look up Character Gardens if you need a gardner. Lee and his team were friendly and the results are good!

Here’s the obligatory before and after shots:

Patio - before it began Finished Patio

They also came and fitted us a garden gate, ours has always been hopeless and it actually fell off its hinges about 3 months ago. Now I have a shiny new one with a catch that goes “click” when you close it.

Garden Gate

(and look, my lavender hedge is getting bigger!)

Updating Memcached on Ubuntu Jaunty

I’ve been working with memcache-related things lately and ran into a problem where the library I was using just didn’t seem to do what its documentation said it would. It turned out that it was making a “gets” call rather than a “get” call – and this functionality wasn’t introduced to memcached until version 1.2.4. Closer inspection shows that although Ubuntu Jaunty Jackalope (9.04) is only a few months old, and memcached 1.2.4 is about 18 months old, its not included and Ubuntu versions Hardy, Intrepid and Jaunty all had 1.2.2 version of memcached.

Credit to the Ubuntu people for resolving this issue already – since memcached 1.2.8 is currently pencilled in for Karmic Koala release of Ubuntu later this year – but I can’t wait that long so I updated my own memcached, it was pretty easy so here are the steps in case anyone else wants to do the same.

  1. download memcached from http://www.danga.com/memcached/download.bml
  2. check you have the dependencies you need. The only thing I didn’t have was the libraries for libevent, which you can install through aptitude with aptitude install libevent-dev
  3. compile as you usually would: configure/make/make install

The final step is to get memcached running – I actually did aptitude remove memcached to get rid of my old version and stop myself from being confused later. Then to start it from command line I used:

/usr/local/bin/memcached -m 64 -p 11211 -u nobody -l 0.0.0.0

The above worked for me and allowed me to use the functionality available in the newer library (specifically I was looking to use the cas (compare and swap) functionality in the new PHP memcached extension) – it probably works on other distros too but I didn’t test it, if it works for you or if you have anything to add then please leave a comment!

Dutch PHP Conference

Often when I attend PHP conferences, I blog as I go along, upload a few photos and generally share with others who aren’t in attendance. At DPC this year I completely failed to do any of the above – no excuses, I was just having too much fun :)

I travelled over on Wednesday and met up with a bunch of colleagues/friends at the airport, so we could make our way to the hotel together. We arrived to find colleagues and speakers already in the bar and it was great to see so many old friends and meet new ones. Thursday was tutorial day, this is a separate day with in-depth sessions that run all day. I attended the Zend Framework tutorial delivered by Matthew Weier O’Phinney from Zend, which was really good. There was a similar session last year but that was quite basic – since then I’ve worked a bit with Zend Framework so this session suited me really well and showed me some stuff that I’ve been struggling with. We rounded off the day with an Ibuildings social, giving me chance to catch up with my colleagues and enjoy the free bar (thanks Ibuildings, great opportunity to see everyone!).

On Friday the sessions got off to a flying start with the keynote from Andrei Zmievski, Open Source Fellow at Digg. One thing that I always find simultaneously wonderful and intimidating is how the speakers at these events mingle with everyone regardless of how qualified they are. This creates a great atmosphere at the events, and makes the speakers very available. You couldn’t pay for the experience of running into someone in the bar whose talk you saw and having them happy to answer a couple of your questions about it. I have no idea if this happens in other industries but it surprises me every time.

Probably the biggest “problem” at this conference was the excellent schedule. Its a good problem to have but it does mean that I had issues with every session deciding what I wanted to see – more so than any conference I’ve been to yet (are you listening, conference organisers?). I only sat out for one of the time slots and that was mostly because I was very tired and the talk I wanted to see was packed :) Friday ended with a happy hour social at the bar next to the venue, which was great – it seemed like all the speakers and most of the attendees were there, and everyone was moving around and talking to everyone else, which was a lot of fun.

Saturday was more great sessions and held a couple of highlights for me – two friends of mine, Ian Barber and Juliette Reinders Folmer, gave their first conference talks at DPC this year, in consecutive sessions. I was able to attend both sessions and they were both excellent (and handily they both spoke on subjects I was interested in!) – and I even managed to put my head around the door of the Oracle Installfest which was also happening through Saturday morning. Saturday afternoon saw the last of the sessions and a closing keynote entitled “The Cal and Ivo Show (with friends)”, in which Cal and Ivo talked over a couple of points between themselves and then invited some of their “friends” onto the stage to be asked a few questions. It turns out I fall into the “friends” category so despite the fact that I wasn’t there as a speaker, I still managed to find myself on stage with a microphone!

I’m a big fan of conferences, I like to get to a few each year. Sometimes I’m an attendee, sometimes a speaker, and sometimes an organiser – if you’ve seen me talk about communities, professional development, or speaking then you’ve probably heard my thoughts on these events and how much can be gained whatever the reason that you attend. DPC is a pretty special event – Amsterdam is well connected and we had attendees from all over Europe, some from the US, and even a few from further afield! The sessions, as I say, were the best I’ve seen and I wish we could do it all again so I could try to get to the bits that I missed. Its a great crowd at the Dutch PHP Conference, always someone to talk to and I actually know quite a few people who attend – and I don’t often manage to see some of those as they live elsewhere in Europe.

I hope everyone who attended had as much fun as I did – see you all next year!

Creating a Banner Bag

Often at PHP Conferences, the organisers are good enough to give PHPWomen a table, and we have a banner we use on these occasions.

PHPWomen stand

Its kind of an annoying thing to lug around with me – its about a metre high and usually travels in a cardboard tube. I’ve been all over the place with it, had to shorten the tube to get it in my suitcase for going to London this year, and then when you get to a place you still have to carry it and its awkward. So, I made a bag for it, ready for this week’s trip to DPC in Amsterdam.

One Banner Bag

Its along the same lines as the yoga mat bags that I keep seeing patterns for – just a tube with a circle at the bottom to make it a cylinder, some webbing sewn into the seam to make a strap and a cord to pull tight at the neck, I took some pictures as I went along.

Bag Template Cord Sleeve
Bag Tube with Handle Radial Pins

First I cut out a rectangle, longer than the tube by about 4 inches and wide enough to go round (very easily round). Then I made the little pocket at the top for the cord to go through (best to do this first as otherwise you’ll probably sew it shut later – thanks mum!). Once you’ve made the pocket then you have a right side and a wrong side, this next bit is easy to get wrong so pay attention! Lay out the rectangle with the right side up. Lay the strap ends against an edge, then fold the other edge over to meet and make the seam – you should have the hem of the cord sleeve on the outside, and a tube with the strap hanging in the middle of it, now pin straps and seam and sew. I went back and forth a couple of times over where the straps were attached.

Time for some maths!

First measure across the tube with it flat. Double that number and you have the circumfrence of the shape you need for the bottom of the bag. So, divide that by 2 times pi (6.283 ish) to get the radius of the circle to cut out. Don’t forget to add seam allowance to this. I had a compass to make my circle but a piece of thread and a pencil would do in a pinch. Once you have cut out the circle, put loads of pins in facing outwards, and then sew round the outside, over the pins. Turn bag the right way out, thread cord through sleeve, and you’re done :)

I just hope it hangs together for a while, got a few conferences to get to this year!

DPC09: Looking forward to the Dutch PHP Conference

This time next week I’ll be full of new ideas and enthusiasm as the Dutch PHP Conference 2009 will have ended. Last year was the first time I attended the event and I have memories of a great crowd and some fabulous sessions, also my first experience speaking at a conference (yes really, a year ago!). This year it looks like the event will be better than ever with an extra day and a schedule absolutely rammed with fabulous content. And best of all, I work for Ibuildings, so I get to attend (I’m not speaking this time around).

Conferences are a great opportunity to meet some like-minded people, find a peer group to drink socialise with, and of course get to hear all the sessions that are around and chat to the speakers. Amsterdam is a great place to do this, its well connected and there are speakers and attendees from right across Europe and beyond. Since I know the PHP community quite well, I’m looking forward to getting to spend time with this cool crowd – and of course all my developer colleagues will be there as well so a party spirit is guaranteed :)

There’s a few other things going on around the main conference – with social events and add-ons like the Oracle Installfest. I hear there are still tickets remaining so if you’re feeling a bit left out – come and join us! If you’re there, do stop and say hi to me – I know more people this year than I did last but its always nice to meet new faces too. Next stop, Amsterdam!

PHPNW09 – PHP Conference in Manchester

Last night at the PHPNW user group we announced this year’s conference – PHPNW09. We don’t have a lot of detail but here is a run-down of all the information I have:

  • Date: Saturday 10th October 2009
  • Location: Manchester Conference Centre. It’s a new venue but just as central and actually easier to get to.
  • Website: http://conference.phpnw.org.uk which currently points at last year’s conference but feel free to click around to get a feel and we’ll update that soon.
  • Focus: PHP in the team – we’re having a real focus on PHP teams, tools and practices for them.
  • Price: We’re aiming for the Early Bird tickets at 50 GBP + VAT, similar to last year (OK so last year was inc VAT but hey, it’s still excellent value). This price will run until 10th September, a month before the conference, at which point they’ll become more expensive.
  • Speakers: Yes please! Like last year, we’ll be running a call for papers and we’ll be looking for some well-known speakers and some we haven’t heard of yet. Like last year the speaker’s package will include the speaker’s dinner, a conference pass and hotel accommodation, but won’t include travel expenses – if you are interested then look out for a CfP in August
  • Schedule: See previous point ;)

Did I miss anything? If so, drop me a comment.

The timescales (all subject to change for no apparent reason and without warning) are something along the lines of getting the site live in June, the tickets on sale in July, the CfP out in August, closing towards the end of that month, publishing the schedule at the start of September to give people chance to get tickets still on the early bird rates which expire on 10th September – then another month for people who like their tickets more expensive and finally the event itself on 10th October.

A few other things I would like to mention:

  1. We want sponsors, including some quite small ones! If that’s you, please contact us or just leave a comment with your details
  2. We will need some volunteers on the day, all of whom get free entry – again, let us know if you are up for that
  3. We’re considering running a “day 0”, probably a hands-on day on the Friday, currently we don’t have either venues or clear plans for this so if you have any thoughts or ideas, add a comment!