Over the last four weeks, I’ve been plagued by numerous PHP segfault problems – multiple versions of PHP, on different operating systems, on different hardware, and running completely different codebases.
Yesterday, I ran into a segfault that I couldn’t work around. It is happening with Apache + mod_php, running inside a Centos 6-based Docker container. Docker is hosted on Ubuntu 15.04.
Here are the steps I took to enable core dumps for Apache inside the container, so that I could examine the segfault.
On Ubuntu (the host machine):
- sudo sysctl -w fs.suid_dumpable=2
- sudo sysctl -w kernel.core_pattern=/tmp/core-%e-%s-%u-%g-%p-%t
That’s it. Your Docker container automatically inherits these settings, and Apache will start coredumping without being restarted.
Why Does This Work?
With Docker, because it’s not a virtual machine in the way that VMWare or VirtualBox is, the container inherits the settings of your host operating system. Inherits, and can’t change them inside the container (which is not ideal).
You have to enable coredumps on your host operating system.
Ubuntu 15.04 ships with coredumps already enabled. Ubuntu also ships with an app that gathers coredumps and ships them off to Canonical for inspection – this is the ‘A system error has been detected’ dialog box that appears all too frequently on a modern Ubuntu system.
Ubuntu’s helper app can’t intercept coredumps that occur within a Docker container, so you don’t have to worry about it in there.
I’m back from this year’s PHP North West Conference, and finally have a few moments to talk about what was (yet again!) another excellent year.
I was there to present two talks – Introducing a Quality Model For MVC Applications, and Ways To Measure Your ORM’s Cost. It’s the first time since the php|cruise back in 2004 that I’ve presented twice at the same conference, and brings me up to something like 15 unique talks and workshops presented over the last 11 years.
I want to highlight one talk in particular from this year’s conference – Matt Cockayne talking about being a good code scout. This talk got promoted from the Unconference track to a spare slot on the Sunday morning. I’ve been thinking about pitching a keynote about how we all need to be great ambassadors for PHP, and I think Matt’s message would make a great keynote for our community.
Whether I’m speaking or just attending, I always enjoy the PHP North West Conference. Their conference team always do everything that they can to make each conference the best that it can be. In my opinion, the explosion of quality, community-based PHP conferences in Europe owes much to the example set particularly by PHP North West. We’ve come a long way from when I started speaking back in 2004
I’m really grateful that conference committees here in the UK – both PHP North West and PHP UK – continue to give me opportunities to come and talk at their conferences. Whether it’s about the problems of framework lock-in, component-based architectures, Git workflows, or indeed about driving quality, I’m often talking about things years before the PHP community moves that way. My work is often about solving problems most people don’t yet realise that they have, and that can’t be an easy sell, both within the committees that select talks for conferences nor to attendees when they’re buying their tickets.
This year’s conference may be over, but there’s no rest to be had.
- I’m already preparing another talk to deliver to the PHP Oxford user group later this month, called “Why Do We Test?” – expect plenty of ethical dilemmas in this one
- November sees me once again volunteering at Aberystwyth University, coaching 2nd year Comp Sci (and related) students on job hunting
- I’ll be speaking at PHP Surrey at the start of January 2016, possibly on writing a test suite for PHPFastCGI – you should come just to watch Andrew give his PHPFastCGI talk, it’s cry-out-loud funny
… and I’ve promised both Glasgow PHP and The Edinburgh PHP User Group that I’ll come up and present to them before the end of 2016.
This afternoon, I’ve seen several folks on Twitter sharing a well-meaning story called Please Don’t Buy A DSLR. Each time, the tweet echoed the same sentiments: DSLRs are too difficult to use, and they’re too large and bulky.
And that got me thinking.
You see, the SLR as a platform is one that I’ve grown up with. I’ve been shooting with SLRs for the best part of 20 years now. The SLR isn’t just my camera of choice, it’s the one that I know best. Hopefully some of that comes through in the photos I’ve posted here over the years.
But it also means that I don’t see the SLR in the same way that you do, if you’ve been using your camera phone or point-and-shoot compact to date. I’ve never seen the SLR that way, because it was my first kind of camera.
I’m not sure if I’ve ever given much thought to whether a DSLR is too bulky, or too difficult to use. Well, there was that one time I was shooting with a monster Sigma 400mm lens …
Are DSLRs Too Large And Bulky?
Well, the fact that I need a dedicated camera bag alone makes it hard to argue against the idea that it’s bulky. The camera and lens straddle the entire width of the backpack. There’s nowhere for a dedicated macro lens to fit. And the 400mm zoom lens that I have my eye on? I’ll need to find a bigger backpack before I can buy that. My camera bag is already much bigger than my hiking rucksack.
This thing is heavy too. I hurt my right arm earlier this year moving an old amp that I was getting ready to sell on. Until a couple of weeks ago, I couldn’t handle my DSLR camera body and lens because of the weight. I’m not sure how long it will be until I can try an all-day shoot again.
So yes, DSLRs are undeniably large and bulky. But are they too large and bulky? I think that depends on whether you see yourself as a photographer, or whether you prefer to take photos.
When I go out with the camera, I’m going out specifically to do photography. The camera isn’t tagging along on some other adventure. The camera is the reason why I’m going out in the first place.
The majority of my camera bag is taken up by my lens collection. With the DSLR, I can switch lenses to suit my subject and my distance from the subject. I get real zoom, not a fake digital one where you’re losing detail or image quality. I get precise control over what’s in focus in the shot, and what’s out of focus – a key part of the artistic side of photography.
A perfect example of what I mean is this shot taken last year in the Brecon Beacons.
In this photo, I’ve been able to make Mike the subject of this photo by making him the only part of the shot that’s in focus. At the same time, the photo works because you can still see what he’s doing – trying to capture Llyn Cwm Llwch on his camera phone. That was possible because I could use the zoom the frame the photo.
The rest of the bulk is the camera body itself. Combined with my lenses, I can shoot handheld in moonlight …
… or handheld in a conference hall (it’s so dark the laptop screen is the main source of light!)
… or I can take shots like this.
When it comes to challenging conditions like these, you can’t overcome physics. You need to gather enough light to have an image to capture. You need large lenses to gather that light, and you need a large sensor to capture that light without capturing too much visual noise at the same time.
Try and replicate these shots yourself on your camera phone to see for yourself.
Are DSLRs Too Difficult To Use?
To deliberately take a great shot with a DSLR, you need both technical mastery of your camera and artistic mastery of the medium. Of the top of my head, this includes:
- ISO speed – sensitivity setting of your sensor
- aperture size – controlling the amount and angle of light hitting the sensor
- shutter speed – controlling the length of the exposure when you take your picture
- focal length – to frame your shot
- focal length combined with distance to subject – to control visual distortion
- focal length combined with distance to subject and aperture size – to control depth of field
- focal length combined with ISO speed and shutter speed – to control camera shake
- height of the sun – to influence the colours in the photo
- angle of the sun – to control the blue of the sky
- angle of sunlight reflecting off the subject – to control highlights and shadows
- the histogram in the camera – to check for good contrast and exposure without over-exposing the shot
- image composition – who or what is the focus of the photo?
- image background – what else is visible in-frame?
- timing – what is moving? where is it moving to? where do you want it to be when you click that shutter release button?
- breathing – keeping the camera still so that the shot isn’t blurry
… and so on. Boy, does that seem like a lot of things to be juggling at once when taking a photo. No wonder photography seems hard!
I’m going to let you in on a secret. The whole time I’ve been taking photos, I’ve only once managed to capture exactly the photo that I wanted to. Once. Here it is.
That’s a shot from the end of the road I live on, taken during one of the rare winters where we actually had enough snow to be worthy of the name. Previous weekend, we’d driven along the road on the way to do Christmas shopping, and I’d pictured that exact scene as we carefully made our way out. It’s the one and only time that the final image is 100% what I wanted to capture.
If you’re interested, that’s a success rate of less than 1 in 10,000. It might be closer to 1 in 50,000.
It doesn’t mean that the other 99.99% of my photos aren’t good. With well over 1,000,000 views on Flickr to date, I must be doing something that you like. But yeah, taking photos is hard. Here’s some examples to show why.
That shot was taken (handheld again!) one evening in London. There was the technical challenge of shooting at night, where one stable primary light source (the sun) is replaced by lots of competing and sometimes chaotic primary light sources (street lights, shop displays, passing vehicle headlights). The subject is a silhouette of a passerby, reflected in the window of the Museum of London. I had to frame the shot, work out the required exposure, find an angle to manage reflections, all before the passerby had walked by.
That shot was taken on a walk through the woods at Beyond the Border one year. The main technical challenge was getting precisely focused on the light whilst throwing the leaves behind out of focus. Then there’s the need to find an angle to show the electric cable. It’s black, and could easily disappear because I’m reducing the amount of light that hits the sensor in order to show up the filament of the bulb.
Some flowers planted in a display at the Eden Project. Should be very simple, right? But what about the shadow being cast by that low sun? The shadow means that the part of the flower that’s nearest the lens is much darker than the leaf on the other side of the plant – and that’s reflecting the sun quite brightly. What’s the best angle to capture the flowers and their stems? Did you notice the building’s wall in the background? Did you notice the lines running along the wall? They’re as much a part of the photo as the flowers are.
My last example – a wing walker putting on a show at the Bristol Balloon Festival one year. Any time there’s sky in the photo, I’m thinking about where the sun is. The camera sees a different shade of blue depending on the angle between the sun and the lens. I need to hold the camera steady enough whilst tracking a moving object. Empty blue skies make for boring photos. I need to wait until there’s clouds in shot to make the background more interesting. I need to wait until the moment the wing walker is doing something that will look interesting in a still photo.
In each and every photo that’s worth publishing, from the simplicity of some flowers in a display to the complexity of one of the world’s leading cities at night, there’s always a lot that the photographer has to do to get the shot. Some of it is technical, and some of it is artistic.
If you replace a DSLR with a different kind of camera, does anything become easier? Well, in a word, no. At no time in any of those photos was the DSLR adding any complexity to the shot. If anything, the DSLR often made these shots easier. I’m not sure that any of them could have been duplicated on a camera phone, or on a compact camera that didn’t offer full control over shutter and aperture speed. And several of those shots benefitted from being able to use lenses that you can’t get on camera phones or compact cameras.
The complexity is inherent to photography as an art medium, and is down to physics (light) and composition (artistic taste). All that the DSLR does is expose you to that complexity. Nothing more.
Other Points In Favour Of DSLRs
The DSLR platform brings some important advantages over other types of camera.
I’ve already mentioned physics – the gathering of light, and the capture of light whilst controlling noise. Indoors, late at night, or more northernly or southernly you go, this becomes more and more important. It’s nearly always very dark indoors, and by definition it’s dark outside late at night. No surprises there. But, if you live in Canada or the States, you might not realise that it’s much brighter outdoors there than it is here in Europe. We’re much further north than you are. That makes it much harder to take good photos with smaller kit.
Phase detection auto-focus systems are, for me, the next advantage of the DSLR platform. This is an old technology, but it works almost flawlessly. And it’s fast. By contrast, contrast-based auto-focus systems are slow, inaccurate, and struggle to track subjects well or work in low-light. I’m sure that one day there’ll be enough computing power in cameras to overcome these problems, but right now they’re very hit-and-miss systems.
I must not forget manual focus. The ability to switch the motor off, and dial in the focus entirely by hand is an important artistic tool when combined with manual aperture control. Works best if you’re lugging around a tripod (more bulk!).
Inter-changeable lenses are important. Other platforms (notably micro four-thirds) also have inter-changeable lenses, but only the two leading DSLR platforms (Nikon and Canon) have an extensive range of lenses both from the manufacturer and from third parties such as Sigma. And the quality of those lenses … oh my.
I haven’t mentioned flash photography, as it isn’t something I do. But it’s another area where the DSLR platform offers a major advantage over other camera types.
DSLRs are very versatile tools. You can mix and match bodies and lenses to optimise for the kind of photography that you enjoy the most.
This is all good stuff, but it isn’t what prompted me to post in defence of the humble DSLR.
I work in tech, and it pays for my photography hobby. Over the last few years, there’s been a steady rise of a culture that I wasn’t aware of before. Somehow, it’s become acceptable not to know what you’re doing or how anything works. Sometimes it’s presented slightly differently – that’s there’s far too much for anyone to know – but the sentiment is the same. We’re moving from the days of the meta-ignorant to an active cult of the ignorant.
As many of the people I follow on Twitter work in tech, it is this culture spilling over into photography that I saw this afternoon. And honestly, I’m deeply deeply uncomfortable with the notion. It isn’t a culture that I grok.
Because I don’t understand it, I don’t want to call “bullshit” on it, and I don’t want to call people out who promote this culture. I don’t walk in their shoes, and I don’t see things through their eyes. I don’t know what the barriers are that are stopping you from learning the things that I have been able to learn.
The best I can do is offer to teach what I know. So, if there’s enough interest, I’ll make the time to put together an easy step-by-step course to the humble DSLR and basic digital photography. It’ll be a group course, run online, and there will be plenty of homework involved.
Just let me know if this is something you want.
I’ve given several talks to user groups over the last few months, around the topics of testing and performance. I hope that you find them interesting and useful.
When To Mock
Mocking has not only become a mainstream practice in recent years, it has also become the default practice for many developers. In this talk, I present three questions that you should ask yourself first whenever you’re deciding if a mock is the right way to test your code, and some insight into how over-mocking ends up making your tests no better than having no tests at all.
This talk was presented to PHP Dorset in November, 2014.
How Much Does Your ORM Cost?
Whenever you use an ORM, you’re trying to reduce the time it takes to ship your code. But what are you trading in return? This lightning talk introduces the idea that ORMs aren’t entirely “free”, and hopes to start you thinking about how you might go about measuring just how much that ORM is really costing you.
This talk was presented to PHP South West (where I was once the answer to a pub quiz question – my claim to fame!) in April 2015.
The Mad Science of Testing
I’m a firm believer that good testing is also good science, and in this talk, I hope to convince you too. And if we’re going to be scientists, we might as well be mad scientists, because they have all the fun
This talk was presented to PHP Berkshire in June 2015.
Back in 2009, I spoke at the PHP UK Conference about the pain of living with PHP’s fledgling frameworks, and I returned in 2011 to promote component-driven applications:
Back then, PEAR was the only tool available for distributing components. It was built in a time when hosting and sharing code was hard, and although PEAR made it possible to create components in PHP, PEAR never made it easy to do so.
Phix was an open-source tool that I wrote to sit on top of PEAR and make things easier. It gave you an easy-to-use build.xml file for Phing to automate all of the common tasks, a standardised file layout so that you could just drop in your code, and integration with Pirum so that you could build and publish.
Today, we don’t need any of these tools. PEAR has been replaced by Composer, and it’s so easy to use that there’s no need for Phing or a build.xml file. The PHP FIG standards have given us our file layouts, and as for publishing … today, all you need to do is push to GitHub and publishing happens automatically.
We no longer need Phix, and that’s a good thing.