Learn More About PHP And The Web Platform!

Struggling with your web server, or to scale your PHP application to meet growing demand?

Whether you're running one server or a whole server farm; whether you're hosting on Windows Server or on Linux.

Learn from Stuart's experience with system design, delivery, support and management to help you do a better job and have an easier time.

Beneath Whitby breakwater

JSON Notation for PHP 7.0

Posted by Stuart Herbert on July 9th, 2016 in Uncategorized.

tldr; I’ve been experimenting with the PHP interpreter, and I made a thing …

JSON is by far the most common API request format. I design, build, and fix API servers for a living. I write a lot of API tests as a result.

I often find myself wishing that I could write JSON directly in PHP code like this:

$payload = {
  "hello": {
     "fish": $fishType

This would save me a lot of time when I’m copying examples from API documentation or JIRA tickets into my test suites.

You’ll find a patch that adds this to PHP 7.0 here: diff against PHP-7.0 tracking branch.

Some caveats: I’m no expert on the internals of PHP, and this patch is very naive. It probably breaks things in ways that I’m not aware of. It passes the PHP test suite locally, but that doesn’t mean you should be trying this in production.

Here’s some examples of what it allows you to do:


// this is an array syntax that PHP
// already supports
$a1 = [
  "hello" => "world"

// and this should be an array too now
$a2 = [
  "hello": "world"

// this is forced to be an array
$a3 = (array){
  "hello": "world"

// and this should be an object
// you can still use array assignment inside
$a4 = {
  "hello": "world",
  "goodbye" => "everyone"

// this should be an object inside an object
$a5 = {
  "hello": {
     "fish": "trout"

// create an array of objects
$a6 = [
        "hello": "world"
        "goodbye" => "everyone"

// this is an object that contains an array
$a7 = {
    "hello": [

// we can still cast nested arrays to objects
$a8 = {
    "hello": (object)[

// we can pass data objects as arguments too
function provide($arg1) {
    return $arg1;
var_dump(provide({"hello": "world"}));

// we can define and return data objects
// without having to assign to a var first
function returnObject() {
    return { "hello": "world" };

Let me know if you’d also find this useful. If there’s enough interest, I’ll see if I can convince someone who is involved in the world of PHP.internals to help me get this turned into an RFC.

Be the first to leave a comment »

Last week, I gave a talk at PHP Cambridge on how to go about setting up and running a positive code review. A huge thanks to Jo for inviting me to speak on this.

We had a great evening looking at the underlying causes of negative code reviews, and what you can tackle to address them. I hope you find the deck useful.

Be the first to leave a comment »

Earlier this month, I gave a talk at the PHP Surrey user group over in Guildford, looking at how to design a functional test.

Be the first to leave a comment »

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):

  1. sudo sysctl -w fs.suid_dumpable=2
  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.

Be the first to leave a comment »

Why We Test: My Talk @PHPOxford

Posted by Stuart Herbert on November 3rd, 2015 in 1 - Beginner, Talks.

Last week, it was my pleasure to present a new talk to the PHP Oxford user group, called “Why We Test”. A huge thanks to Oliver for inviting, and to everyone who came along.

Be the first to leave a comment »

Another Fantastic PHPNW Conference!

Posted by Stuart Herbert on October 8th, 2015 in #phpnw.

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.

Are you a good scout? – PHPNW15 Track 3 from phpboyscout

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.

Be the first to leave a comment »

Here is the original blurb for this talk …

Your project has adopted an ORM such as Doctrine because it’s the quickest way to hook your code up to your database. Things are looking up, and your website is about to take off. Aaaand then the first complaints start to come in that your site isn’t coping with the new customers. You can’t find a problem in your own code. Could it be the ORM that’s the problem? How can you tell?

In this talk, Stuart will show you how you can use off-the-shelf open-source tools to work out what your ORM is doing, and whether or not it is the cause of your performance problems. He’ll show you how to measure the database itself and the ORM code, as well as providing useful strategies to reduce the cost of your ORM without having to abandon the ORM altogether. Finally, he’ll show you how you can extend these techniques to other parts of your application, so that you’re never in the dark again.

Be the first to leave a comment »

Here’s the original blurb for this talk …

Your integration, functional and non-functional testing gives you a good idea if your code will work on Production. But how do you go about measuring the quality of code that already seems to work? How do you make that measurement repeatable? How do you share it with clients in government, finance or other large enterprises who are looking for a 3-5 year shelf-life from your code?

In this talk, Stuart will introduce you to SQuaRE, the international standard collection for software quality. He’ll give you a tour of all of the available and upcoming standards in this area, before taking a deep dive into the Product Quality Model from ISO/IEC 25010:2011. He’ll explain what a quality measurement is, how you link them to your project’s quality criteria, and how you incorporate them into code reviews, QA teams and management decisions.

You’ll leave this talk ready to start measuring and improving the quality of your product or service, with the tools you need to not only maintain quality but also to keep increasing it over time, even when faced with staff turnover.

Be the first to leave a comment »

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.

Be the first to leave a comment »

Goodbye, Phix

Posted by Stuart Herbert on March 2nd, 2015 in phix.

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.

Be the first to leave a comment »
Page 1 of 1812345...10...Last »

This Month

August 2018
« Jul