I love you really Apache

I kinda slagged off Apache’s roll in a lot of web applications. The gist of that post is that Apache’s traditional life-cycle has been replaced by functionality within the web app itself (eg the web app handles authentication, rather than the web server). What I totally missed though, and it seems patently obvious now, is that Apache’s ability to be used as an HTTP wrapper for PHP apps is a good thing.

If you take away the logging/resolving/auth/negotiation/etc stages you’re left with a daemon that speaks HTTP. At this “stripped away” stage it receives an HTTP request and passes it through to PHP, which does some processing and then Apache returns an HTTP response. That might not seem like much functionality but it’s an absolutely critical part of a web app. My last post suggested that using Apache in this way was “bloated overkill”:-

We don’t really use Apache for much, so why do we use it at all? I think it boils down to being a nice host environment for PHP. There’s nothing really wrong with that, except PHP is tightly coupled to Apache. I think Apache rocks, but if we just end up using it as a host for PHP, then that’s bloated overkill? What about if we stripped out the features of Apache that we dont use until we’ve got a lightweight http wrapper for our PHP app to run in… isn’t that what Rubyists do with Mongrel?

I’m an idiot. Apache’s ability to be used as an HTTP wrapper isn’t a bad thing: it’s a good thing!

If you view Apache like this then you’ve got a rock solid foundation to create an “HTTP application server” (ie a standalone daemon communicating via HTTP). It’s one of those pieces of software that you can run on pretty much any environment and has been QA’ed over years. It’s solid, trusted and “fast enough”.

I remember talking to Rob Allen about potentially moving to Ruby or Python and one of the barriers for him was reliability. With PHP we can stick scripts in Apache’s docroot and forget about them - they’d probably survive a nuclear winter. Neither of us had the confidence that you could do the same with a Ruby/Pyhon stack (eg running Mongrel or CherryPy).

PHP is like a scripting language for Apache - and that’s a massive strength.

Leave a Reply