PHPNews

Using .vimrc for project specific settings

I'm more of a spaces person than a tabs person when it comes to source code and in Vim, I like to see the tab characters, so I have this setting: set listchars=tab:\⇥\ ,trail:·,extends:>,precedes:<,nbsp:+ This places a handy ⇥ character so that I can see the tabs: I'm currently working on a …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday July 25, 2018


Notes for working on the OpenWhisk PHP Runtime

These are some notes for working on the OpenWhisk PHP Runtime , but are probably applicable to the other runtimes too. Setting up I have a clone of the runtimes I'm interested in and core side-by-side in a directory. You then need various tools for development, which are documented here for macOS & …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday July 4, 2018


Using Fractal as your OpenWhisk API's view layer

When writing an API, it's common to produce an output that conforms to a known media type such as JSON API or HAL , etc. I'm a strong believer that even though I'm writing an API, my application has a view layer. It's not the same as building an HTML page, but you still need to separate out the code that creates …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday June 27, 2018


Dependency Injection with OpenWhisk PHP

Any non-trivial PHP applications use various components to do its work, from PDO though to classes from Packagist. It's fairly common in a standard PHP application to use Dependency Injection to configure and load these classes when necessary. How do we do this in a serverless environment such as OpenWhisk ? This …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday June 20, 2018


Using API Gateway with Serverless & OpenWhisk

As with all serverless offerings OpenWhisk offers an API Gateway to provide HTTP routing to your serverless actions. This provides a number of advantages over web actions , the most significant of which are routing based on HTTP method, authentication and custom domains (in IBM Cloud). Creating routes with the wsk …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday June 13, 2018


Using Composer with Serverless & OpenWhisk

Every PHP project I write has dependencies on components from Packagist and my Serverless OpenWhisk PHP projects are no different. It turns out that adding Composer dependencies is trivial. Let's create a simple action that converts a number to it's string form. e.g. 123 becomes one hundred and twenty three …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday June 6, 2018


Using Serverless Framework with OpenWhisk PHP

Serverless Framework is a toolkit to help you mange and deploy a serverless application. (Personally, I'm not a fan of the name as the word "Serverless" already has a meaning in the same space!) It's a useful tool and supports all the major providers, though AWS Lambda seems to be first-among-equals. The OpenWhisk …

Continue reading »

Written by Rob Allen - - Aggregated on Thursday May 31, 2018


Invoking many OpenWhisk actions from another one

I have a project where I need to store a number of items into a data store. I have an OpenWhisk action that stores the items so I wrote an action that takes advantage of the OpenWhisk JS client library to do invoke my store action once for each item in an array that this action receives. This is the JavaScript …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday March 14, 2018


Using async/await in OpenWhisk

I'm currently writing an OpenWhisk action in JavaScript that searches Twitter using their API . To do this, I need to get a bearer token from one API endpoint and then call the search endpoint. Disclaimer: I'm in no way a JavaScript expert, so I would love it if you could constructively suggest improvements in …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday March 7, 2018


Automated Testing for PHP training course

I'm delighted to announce my new venture, PHP Training , with my friend Gary Hockin . As you can probably guess from the name, PHP Training is a training organisation where we provide public training courses on topics related to PHP. These courses will be held in person, initially at various venues in the UK, and …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday January 17, 2018


Using Composer packages with OpenWhisk

When creating new OpenWhisk actions in PHP, It's likely that you'll want to take advantage of the rich ecosystem of Composer packages on Packagist.org . The OpenWhisk PHP runtime has you covered with some pre-installed Composer packages and also the ability to upload your own using a zip file. Pre-installed …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday January 3, 2018


2017 in pictures

Another year has passed which gives me an excuse to to reflect on what's happened. As usual , I look at the photos that I've taken and frame my thoughts around them. January I started the year with one of my favourite pictures of the kids. I also spoke at CodeMash in Ohio. This was a new conference to me and I …

Continue reading »

Written by Rob Allen - - Aggregated on Sunday December 31, 2017


Run the UniFi Controller headless on Mac

I'm running a UniFi network here with wireless access points, the Security Gateway and a PoE switch. It seems to be a robust system and is almost certainly overkill, but reliability is high on my lists after bad experiences with a NetGear WiFi router. The UniFi system software is called the Controller and runs …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday December 20, 2017


Generating training handouts for printing

When training, I like to provide my attendees with a printed copy of the slides with space next to each one to write notes. This handout has 4 slides to a page, along with a title page and I use pdfjam to create it. Pdfjam is a wonderful command line tool for manipulating PDFs and fits the bill perfectly for …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday December 6, 2017


Implementing CORS in Zend Expressive

On a recent project, I needed to implement CORS support for my Expressive API. The easiest way to do this is to use Mike Tuupola 's PSR-7 CORS Middleware . As this is a standard Slim-Style PSR-7 middleware implementation, we need to wrap it for Expressive, so we make a factory: App/Factory/CorsMiddlewareFacto…

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday November 15, 2017


Customising Whoops in Expressive

I find the Whoops error handler page in Expressive quite hard to read and particularly dislike that the error message displayed in the top left is hidden if it's more than a few words long. To fix this, I discovered that you can provide a custom CSS file to the PrettyPrintHandler and then override to your heart's …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday November 8, 2017


Using Docker to create a MySQL server

When working on test code on my computer, I usually use the built-in PHP server ( php -S ) which works nicely. Every so often, I need access to MySQL and I use Docker to temporarily create a MySQL server for me. This is how I do it. The magic command is: $ docker run --name mysql \ -e MYSQL_USER=rob -e …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday November 1, 2017


OuputBuffer Middleware for Expressive

When developing an Expressive application, if you use var_dump() , echo , print_r() , etc when you get this error: Fatal error: Uncaught RuntimeException: Output has been emitted previously; cannot emit response in /www/dev/rka/example-app/vendor/zendframework/zend-diactoros/src/Response/SapiEmitterTrait.php…

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday October 25, 2017


Displaying errors in Expressive with Twig

If you're not using the Whoops error handler with Expressive and are using the Twig renderer, then you are given no information about the problem that occurred, even in debug mode. To fix this, I changed error.html.twig to this: {% extends '@layout/default.html.twig' %} {% block title %}{{ status }} {{ …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday October 18, 2017


"Software architecture is failing" by Alex Hudson

Alex Hudson 's article, "Software architecture is failing" is a really interesting article and resonates with me as I come across this a lot. I recommend reading it. I'm very much in the camp of designing for the business requirements first and my biggest successes are the apps which solve my clients' problems. To …

Continue reading »

Written by Rob Allen - - Aggregated on Monday October 16, 2017