One of the big features arriving with PHP 5.4 is the addition of a built-in basic webserver for use in development environments. Quite a few of the other scripting languages have something like this so I'm very pleased to see it in PHP. Using a server like this makes it easy to quickly try out some scripts without needing to configure apache or really do anything much! I had to look up a few things to get started, so I thought I'd write them down for posterity. Continue reading
Category Archives: php
Building A RESTful PHP Server: Routing the Request
This is the second part of a series, showing how you might write a RESTful API using PHP. This part covers the routing, autoloading, and controller code for the service, and follows on from the first installment which showed how to parse the incoming request to get all the information you need.
Building A RESTful PHP Server: Understanding the Request
Once upon a time, what seems like a lifetime ago, I was away for a couple of weeks, and I wrote a series of posts about serving RESTful APIs from PHP to keep my blog going while I was away. Fast forward a few years and those posts are outdated and still wildly popular - so I thought it was about time I revisited this and showed how I'm writing RESTful PHP servers today!
In the first part of this (probably) 3-part series, we'll begin with the basics. It might seem boring, but the most important thing to get right with REST is parsing all the various elements of the HTTP request and responding accordingly. I've put in code samples from from a small-scale toy project I created to make me think about the steps involved (should I put the code somewhere so you can see it? Let me know). Without further ado, let's dive in and begin by sending all requests through one bootstrap script: Continue reading
POSTing JSON Data With PHP cURL
I got this question the other day: how to send a POST request from PHP with correctly-formatted JSON data? I referred to the slides from my web services tutorial for the answer, and I thought I'd also put it here, with a bit of explanation. After all, publishing your slides is all very well, but if you didn't see the actual tutorial, I often think they aren't too useful.
Continue reading
Handling SQL Errors in PDO
I love PHP's PDO (PHP Data Objects) extension; it gives a consistent, object-oriented interface to handling all kinds of relational database backends. One thing that annoys me is that the MySQL driver for PDO defaults to a silent error mode which can make SQL errors tricky to spot! Continue reading
PHPCon Poland: Conference Report
At the weekend (yes, this took all week to write), I was on my first ever visit to Poland, in order to speak at PHPCon Poland. They contacted me early in the year to ask if I would consider going along to give my talk Teach a Man to Fish. Continue reading
My Book is Published: PHP Master
I am truly delighted to announce that "my" book is published. Technically it's really "our" book since I had the pleasure of co-authoring with friends and PHP rockstars Davey Shafik and Matt Turland. The book is "PHP Master" and it's a broad-ranging text covering a series of topics that we felt were relevant to PHP developers who aren't beginners, but who are looking to fill in some gaps and get a good grounding in creating whole applications in PHP.
Continue reading
Announcing Training Dates for November
I'm teaching some new public courses next month (in Leeds), so I thought I'd mention them on the blog in case anyone is interested. I'm super-excited because this is the first time I've delivered my own training content as a public course, so even if you aren't in the position where you work with lots of people who need the same training, you can pop along! Continue reading
ArrayAccess vs ArrayObject
I help people qualify for Zend Certification and in the last few months I've had questions about both ArrayAccess and ArrayObject. This post is an attempt to illuminate both.
Continue reading
At the Helm of Joind.in
As of a few days ago, and following Chris' post, I am now the proud owner of an open source project. Continue reading
