Way back when I first dove into web programming, PHP was the obvious choice for my needs. It was available on virtually all web servers, had excellent documentation, and could handle everything I needed to do (and much, much more). These things are even more true today, and PHP is still my middleware of choice. However, I have noticed that the way I use PHP has changed in recent years.
Then came the iPhone.
In 2007, the iPhone kicked off a tidal wave of interest in mobile computing. Like thousands of developers, I was starstruck by this magical little device that put the Web in my pocket. Always connected, first-class browser, intuitive touch interaction — it’s truly amazing, and I wanted to jump in with both feet.
When the iPhone was first announced, Saint Steve told 3rd party developers to build web apps if they wanted to program for iPhone. I was ecstatic about this, because:
- I was a web developer, not a Mac developer.
Of course, Jobs ended up reversing his position less than a year later with the announcement of Cocoa Touch and the iTunes App store, and the holy war between mobile “web apps” and “native apps” was born. Cocoa Touch is an amazing framework, but as a web developer, I’m quite disinterested in developing for a particular platform. So, rather than diving into Xcode and iOS, I dedicated myself to finding ways to craft a web app experience on mobile devices that rivaled the native app experience and was cross-platform.
Okay, so what does this have to do with PHP?
Here’s the thing. My round-trip approach to PHP-based web development became untenable. It’s just too expensive to resend the entire UI to a mobile client with every request. And when I say expensive, I mean it both figuratively and literally — certainly there is an annoying performance lag associated with a full round trip to the server, but a potentially bigger issue is that you’re unnecessarily eating away at the user’s monthly bandwidth allotment. I needed to take the Ajax plunge, and in a big way.
- Division of labor
- Once you’ve set up a server-side API, you can easily have your app designer work on the front end without knowing the slightest bit about PHP, templating languages, or any other server-side technology. Hell, you don’t even have to give the designer access to the server — they can just code against the API with files sitting on their desktop.
- Multiple clients
- The computing landscape is undergoing massive growth and transformation. We are seeing screens as small as a credit card and as large as a billboard. There’s also a big split emerging between devices that support touch input, mouse input, and to a lesser extent voice input.
- The benefits of this approach have been demonstrated by Google, Yahoo, and maybe most dramatically by Twitter, who documented and released a simple API to the developer community at large. Thanks to this, Twitter clients of all shapes and sizes have found their way into every corner of our digital lives. Starting with an API allows this sort of seemingly-infinite flexibility, and I’m sure it contributed greatly to Twitter’s adoption.
- The computing landscape is evolving so rapidly that it’s very difficult to predict what’s coming next. Lots of smart people are working on radical new technologies that will alter the way we interact with computers, and more importantly, each other. Everything from holographic projections of live sporting events to brainwaves as user input are on the table. In my opinion, the best way to stay flexible in the face of surprising new developments is to provide a robust API to handle as much of the backend heavy lifting as possible.
Start with your API
These days, I start virtually every project by defining the API. I’m particularly fond of the RESTful approach, but in practice I usually just roll my own, because it’s so easy to do with PHP. There’s probably a great REST library out there for PHP, but I haven’t had the need to look for it yet.
To wrap up, I’d just like to say that there’s never been a better time to be a web developer. The convergence of ubiquitous connectivity, cloud services, and interactive touch screens are creating an environment where virtually anyone can build compelling user experiences that have a massive reach with very little barrier to entry. So, get back to your text editor and start coding; break time’s over!