PHPNews

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 code: …

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


Pretty print curl -i

My favourite tool for working with APIs is curl and in particular, I like using the -I switch to view the status line and headers too: This generates an output that looks like this: $ curl -i https://api.joind.in HTTP/1.1 200 OK Date: Wed, 04 Oct 2017 09:51:46 GMT Server: Apache X-Powered-By: PHP/5.6.4 Acce…

Continue reading »

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


Converting a Composer dependency to git for editing

I'm adding a new feature to ZF's Problem-Details component and it's easiest to do this within the context of the application I'm developing. The component lives in vendor/zendframework/zend-problem-details and was installed using composer require so doesn't have its own git repository as the distribution zip …

Continue reading »

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


Custom URLs for a Cloud Foundry application

Now that I have my application deployed to Cloud Foundry , I need it to work with my own domain, such as bookshelf.akrabat.com rather than slim-bookshelf.eu-gb.mybluemix.net . We can do this via the command line which is useful. To do this we need to create a domain and then we can create a route . Create …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday September 27, 2017


CORS and OpenWhisk web actions

By default, OpenWhisk will handle the relevant responses for CORS . Specifically, it will respond to an OPTIONS request with these headers: Access-Control-Allow-Origin: * Access-Control-Allow-Methods: OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH Access-Control-Allow-Headers: Authorization, Content-Type …

Continue reading »

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


CLI credentials for a Cloud Foundry database

If you need access to your Cloud Foundry database from the command line the easiest way to get a set of credentials is to create a service key . This is done using the command cf create-service-key {service-name} {key-name} . You can call the key anything, so to connect to my database that I created previously: …

Continue reading »

Written by Rob Allen - - Aggregated on Monday September 11, 2017


Using PostgreSQL with PHP in Cloud Foundry

Having successfully deployed a PHP application to Cloud Foundry , I needed a PostgreSQL database for persistent storage. I found Lorna Mitchell's Connecting PHP to MySQL on Bluemix helpful and this article expands on that information. I want to create a cloud-based PostgreSQL database and connect it to …

Continue reading »

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


Deploying a PHP application to Cloud Foundry

I recently had a requirement to deploy a Slim application somewhere. As I already have a Bluemix account, it seemed sensible to deploy it to their Application Runtimes service which is an installation of the Open Source Cloud Foundry project. This turned out to be quite easy, but there are a number of steps …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday August 30, 2017