PHP Tag

licenceToKill A few months ago I joined an exciting project with fellow Shiner Graham Polley, who you might know from such hits as Put on your streaming shoes. This is a follow-up article, discussing the elegant way in which we solved a hideous asynchronous limitation in PHP. My role on the project was DevOps-based, and I was there to build some infrastructure using Amazon Web Services. As the cool kids would put it, I was there to put our client's enterprise application INTO the cloud, or, more succinctly, to build a solution coupling services from two rival cloud service providers and provide a new league of scalability and flexibility. The solution was pretty simple, but, like any simple solution, the little complexities come out along the way, and when you're least expecting them.
Saturday-Night-Fever-2

The Kick-Off Meeting

It went something along the lines of:
  • Client: "We have a new requirement for you.."
  • Shiners: "Shoot.."
  • Client: "We'd like you to come up a solution that can insert 2 million rows per hour into a database and be able to deliver real-time analytics and some have animated charts visualising it. And, it should go without saying, that it needs to be scalable so we can ramp up to 100 million per hour."
  • Shiners: [inaudible]
  • Client: "Sorry, what was that?"
  • Shiners: [inaudible]
  • Client: "You'll have to speak up guys.."
  • Shiners: "Give us 6 weeks"
We delivered it less than 4.
phpclaw As a newcomer to PHP I was puzzled by how to unit test controllers and services when using Silex (if you're wondering, Silex is based on the Symfony 2 framework and draws a lot of modules from it). In this post I'll talk about my experiences getting tests going, and how you can setup your own unit tests using PHPUnit and WebTestCase. I'll start with my initial attempts to test directly against the DB, and the approach that I ultimately found most useful and practical. I've also created an example Silex project that can be used to try out the various features of PHPUnit. The only prerequisite is PHP 5.4, which comes with most modern OS's. You don't even need Apache installed to try it out!