This month we have Reshma Sohoni from SeedCamp and Jennifer O’Grady from Democracy PR – and I can’t wait to hear both these women speak and hear their stories. The details are all on the website but in short the event starts at 6pm, its at The Loft Leeds, and I hope I’ll see you there!
Presenting Under Linux: xrandr
I’ve been a linux user for a few years now but when I started working for Ibuildings I started giving presentations, either as a speaker or when delivering training – and for a long time I used to boot into Windows for those, using a VM if I needed to code.
The main reasons I wasn’t comfortable using Linux to present were:
- I have Powerpoint and I use the presenter view a lot
- Linux doesn’t automatically find and configure monitors like Windows can.
Since Ubuntu Intrepid Ibex (8.10), its been possible to reconfigure screen in Linux without restarting X. But I was kind of scared of xrandr and I still liked the Powerpoint presenter view so I just carried on with windows. Then I realised that Open Office had also released a presenter view and I gave it a try. With one obstacle removed it was time to learn to work xrandr, which means I can also work external monitors without fiddling with xorg.conf, very useful. I’m now pretty confident with it so here’s the benefit of my wisdom*
xrandr
The first thing to do is figure out what you have and what your options are. So plug in the second screen and run xrandr with no arguments. On my system I get something like this:
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 2560 x 1024
VGA connected 1024x768+0+0 (normal left inverted right x axis y axis) 338mm x 270mm
1280x1024 60.0 + 75.0
1024x768 75.0* 60.0
800x600 75.0 60.3
640x480 75.0 59.9
720x400 70.1
LVDS connected 1024x768+0+0 (normal left inverted right x axis y axis) 304mm x 190mm
1280x800 60.0 + 50.0
1024x768 85.0 75.0* 70.1 60.0
832x624 74.6
800x600 85.1 72.2 75.0 60.3 56.2
640x480 85.0 72.8 75.0 59.9
720x400 85.0
640x400 85.1
640x350 85.1
HDMI-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)
This shows VGA (your external output) and LVDS (the laptop screen) and all the various modes they support. I sometimes see output under HDMI-1, and this seems to cause problems so I always turn off this output by running:
xrandr --output HDMI-1 --off
Next I send a command to set the resolutions on both screens. For projectors I tend to go with 800×600 as this almost always works and it means the text on my laptop screen is then so large I can see it from several feet away!
xrandr --output LVDS --mode 800x600 --output VGA --mode 800x600
Its perfectly fine to have different resolutions on both machines but bear in mind that X has one desktop and will show you sections of it on each monitor so if they’re different sizes you sometimes get either bits missing off one monitor or one of the outputs looks stretched. I don’t really have any general advice with this other than get the projector in the right ratio and then fiddle with the available modes to see what works for you.
To set the second screen to be different from the first (i.e. tiled rather than mirrored), just tell xrandr where you want it.
xrandr --output LVDS --mode 1280x800 --output VGA --mode 1024x768 --right-of LVDS
Again you’ll get sections of a single desktop, not two separate areas, so things might look odd if they are on both screens. For me this command has worked really well since I got to grips with it in the last few months, and I’ve plugged various machines in to various external monitors and given a few different talks. I’m sure there is a lot more to know about xrandr but I haven’t needed it yet – hope this is helpful! If you have any experiences with this or anything to add, just drop a line into the comments form.
* I’m not an expert by any means, but the above works for me on Ubuntu with my Thinkpad T400 and my Acer Aspire One.
PHPNW TestFest
With 14 attendees to support, Scott had his hands full but between all of us we managed 84 tests which was very impressive!! Most people seemed to pick it up really easily and I’m almost certain that there will be a few more tests coming in from various people who were there on the day – which is great because the increased test coverage really does make a big difference to PHP itself.
I’d like to say a huge thanks to everyone who turned up and wrote tests, to Scott for coming and dragging us all through the process with such good humour, to Salford University for lending us the space for the event and to Ibuildings for sponsoring the event and making it all possible! There are a few more photos as well – a huge well done to everyone who took part, here and at the other test fest events!
Looking Forward to php|tek
The tutorial session is a half-day on Tuesday afternoon – I’m co-presenting with Matthew Weier O’Phinney of Zend and our session is “Practical SVN for PHP Developers”. We’ll be walking through the concepts of source control, adminstering subversion, repository structure strategies and also showing some hands-on use of subversion. We’ll talk about the issues around introducing subversion into a team and looking at how this tool fits in as part of the development process. If you’re a subversion user looking to learn to get more fromthe tool, an architect looking to include it in new or existing setups, or a development team leader or manager looking for information about setting up and managing subversion, then come along!
The next talk I’ll give is on Wednesday when I’ll be presenting “Linux-Fu for PHP Developers”. If you’re already a linux wizard then feel free to drop by and heckle – but if you’re either a beginner or a competent user looking to raise your game then this session is for you. Its a tour of the commands I use day-to-day; an opportunity to metaphorically look over my shoulder and take a peek at the tools I use and how I use them. There are code samples and although there is a lot to take in, I hope it will make command-line linux usevery approachable for everyone – if I can do it, anyone can :)
Finally I get to co-present with my friend and Ibuildings colleague Stefan Koopmanschap a session entitled “A Guide to Using and Understanding the Community”. This session is an overview of what happens in the community outside of people’s nine-to-five jobs, how to access the community and what you might find there if you do. A lot of the value of open source software is in the community but knowing what information and interactions you can find there and how to find them is a mystery to many. For business in particular, free software with no guarantees can be slightly daunting! Stefan and I have lots of community involvement and will give a tour of what’s happening, how you or your employees can gain fromthe community, and how you can give back.
I’m really looking forward to the conference, to meeting old friends, virtual friends, and friends I haven’t made yet – if you will be there let me know and make sure to come and say “hi”!
Screen-Profiles – Improved Screen in Ubuntu Jaunty
The first thing to say is that if you have an existing .screenrc file, you don’t get any notification or prompt about the new features of screen, I was lucky and fell over the information. To get to the features:
- if you have a .screenrc, rename it for a moment
-
aptitude install screen-profiles screen-profiles-extras
- run screen
EDIT: From Karmic Koala (9.10) and later these packages are now byobu and byobu-extras – they work as outlined here however, just the package names changed.
The first thing you’ll notice is that there’s a whole lot more stuff going on at the bottom of the screen. I have had a custom .screenrc file which gave me tabs for a while, but now they’re part of the standard setup.
If you look in the bottom right corner you’ll see there’s an “F9 Menu” – yep, screen responds to a whole bunch of function keys! I’ll keep my traditional ctrl+a mapping I think, but you can reconfigure this to your hearts content. And look at the menu itself:
You can change the colour themes (more on that another day, I’m still playing with the settings) and you can also turn on and off a load of different widgets, basically lots of different system information. I’ve got most of it turned off on my laptop (since I already have a battery meter etc) but for a server this could be really useful. Examples:
I’m really happy to see Canonical improving this particular tool, and I wanted to mention it purely because existing users of screen won’t see the new functionality by default which seems like a bit of an oversight. If you’re a screen user, upgrade to Jaunty, try it out, and leave a comment on how it works out for you.
Testing PHP
I’m a linux user, so this whole post relates to how this works for me, on my ubuntu system.
First of all I grabbed a copy of PHP from http://snaps.php.net. The TestFest focuses on writing tests for PHP 5.3 so I took the most recent copy of that version.
I unzipped the code, changed into that directory and compiled the code and ran all the tests:
./configure --enable-gcov
make
make test
At this point I was prompted to send the report of the tests off to the PHP QA team – I always make sure to do this when I compile PHP, it helps them a lot to collect the data and it is no bother for me. I will say that due to the huge increase in the number of tests in PHP 5.3, it takes a bit longer than it used to, but I don’t mind.
One thing which I keep seeing when I see people talk about tests is the lcov test coverage graphs, the ones that look something like this:
“Just pick something to test from there”, people said. I just didn’t understand at all how to pick which bit of PHP I would need to write test code for. It turns out that if you click on an extension, you get a list of files, and these too have coverage numbers.
Then if you click on an individual file, you see the C code of PHP itself there, with highlights to show which lines are executed in tests and which are not. So now you can start to get an idea of what needs testing (although you have to read C to do it which is fine since I’ve studied it, and PHP is pretty similar, but it does get confusing in places).
It is pretty easy to run a subset of tests, despite some quite long-winded documentation on the subject. There is a script inside the PHP directory called run-tests.php which takes an argument of either a single test or a directory of tests you’d like to run. Just call this with CLI PHP and specify which tests you want – I specify the path to the PHP since I want to use PHP 5.3 and not the existing PHP which I already use on my system
export TEST_PHP_EXECUTABLE=/sapi/cli/php
$TEST_PHP_EXECUTABLE /run-tests.php tests/ext/spl/
The “make test” command also takes a TESTS= argument, and this is also an option. Its just a wrapper for run-tests though so either works fine. I built my php inside the directory with the source in it, just for convenience, but you don’t have to – and if you don’t then you need to adjust the paths above accordingly.
Then its time to read the phpt documentation and start writing tests. There are groups all over the world taking part in the testfest, so check the list and find your nearest. For me that’s Manchester, 9th May 2009 – and I’m looking forward to it!
Kubuntu Freezing on Splash Screen after Jaunty Upgrade
The problem was that the files in the ~/.ICEauthority directory were owned by root so couldn’t be written to by my user. I followed the instructions I found on this post where someone had exactly the same problem, and just chowning the whole directory to my user fixed the problem and allowed me to boot Kubuntu.
Hopefully if anyone else has this problem they’ll find either this post or the other one and also find the easy fix! If this works for you, leave a comment.
Auth Mechanisms for Web Services
Quite a lot of services don’t require any authentication at all, similar to quite a lot of the web. In either setting, the information is there for users to consume when they want. However the difference comes when services start doing more than making data available. If changes can be effected by the service, then we need to identify who is requesting the change.
Traditional websites use a username and password, and we can do exactly the same thing here. Services work on a series of discrete requests and its common to require that the username and password be supplied with every request. However for high-load services or where a particularly fast response time is needed, we can use something similar to sessions, where the user first has to authenticate and is given a token. On subsequent requests they supply the token and we wave them through without requiring their credentials again.
There are a number of considerations involved in deciding whether this setup can work for a particular application:
- Does it take time to authenticate? For example is there an external system to wait for or lots of user information to retrieve?
- How guessable is the token? Any kind of reasonable length hashing will help you here. I tend to use salted md5 tokens*.
- How long will the token be valid for? If interaction with the service is likely to be a burst of related requests, you might allow validity for 30 minutes for example.
- Will you require other identifying information as well as the token? For example you might require that the user also supply their username, which would have to match the token. I’ve also seen systems which only accept tokens from the same user ip address as the user’s original authentication call came from.
Also think about storing these tokens. They can go in their own table along with the information you want to use frequently – this is the same idea as storing information about a user in a session, for example. So user id, maybe display name plus the token itself, some information about when it was created or when it expires, and anything else that will be needed to check the token’s validity. With this information being independent and just used to verify the user, there is also the option of storing this in an alternative, faster, mechanism such as memcache.
This isn’t by any means everything there is to think of, but just some ideas of things to consider when designing a service.
* I blogged about salting md5s in PHP recently, if you are interested
Replacement Love-Knot Wrap

Its the same design as before, using a “love knot” or “Solomon’s knot” stitch to create an airy web of a wrap that can be worn either over the shoulders or bundled into a scarf as shown. I used a cotton tape yarn since she’s just about to leave again to go and work in Portugal so woolly wouldn’t be a good choice, this yarn used to be a cardigan I bought but it had daft sleeves so I unravelled them but never did anything better.
The scarf laid out and a closeup of the beads:
Here’s hoping she hangs onto this one at least as long as she managed for the last – safe travels, little one!
Quiet Diff
diff -ur dirA dirB
The result was large and messy and included a lot of .svn files (long story). So to get an idea of how many files had differences I ran diff with -q for Quiet. This just outputs one line per changed file and also a line for if a file only exists in one or other directory. I then used grep to ignore any lines with .svn in them, and finally passed the whole lot to wc (for Word Count) to tell me how many lines there are.
diff -urq dirA dirB | grep -v .svn | wc -l
If you get a number greater than zero, your codebases are not identical and you have discovered why your fault is “intermittent”.