Latest stories

Icinga Web, Could not send command. Check if your webserver’s user has correct permissions for writing to the command pipe.

If you are getting this error when trying to perform actions on services or hosts in Icinga Web, most forum posts point to the configuration being correct, etc. Firstly make sure that the command pipe referenced in access.xml points to a valid place, and has icinga-cmd:icinga ownership vim /usr/local/icinga-web/app/modules/Api/config/access.xml <!-- allowed to be written to -->...

Icinga Web, Uncaught AgaviLoggingException thrown, Cannot open file “log/debug.log”

When trying to get Icinga Web to work, you may run into issue with the log directory not being writable Uncaught AgaviLoggingException thrown Cannot open file "log/debug-2014-01-28.log", please check permissions on file or directory. It doesn’t appear to be referencing the core directory, or any other relative directory, so the easiest fix is to create an absolute path to where...

Icinga Web, Set correct write permissions for directory “/usr/local/icinga-web/app/cache”

If you have followed the Icinga install procedure through as per the installation documentation, and are having difficulty getting Icinga Web to install, you may eventually get an Agavi error saying that the cache directory is not writable (if you find the PHP errors) AgaviCacheException Failed to write cache file "/usr/local/icinga-web/app/cache/config/config_handlers...

Add URL query parameters to links using view helper in Zend Framework 2

There are 2 ways to add query parameters using the URL view helper in Zend Framework 2, either using Segment route placeholders, or adding them as normal query parameters (e.g. url?id=1&name=barney) Which one you need to use depends on what route the view helper is being used on; since all URL’s in Zend Framework 2 need to be route-aware (even if you’re mimicking ZF1 routing) it...

Sports Points on DailyProgrammer

Here is my solution to the Sports Points code test on r/dailyprogrammer You must write code that verifies the awarded points for a fictional sport are valid. This sport is a simplification of American Football scoring rules. This means that the score values must be any logical combination of the following four rewards: 6 points for a “touch-down” 3 points for a “field...

Mock a JSON HTTP API response in a PHPUnit unit test for Zend Framework 2

In order to mock an API in a unit test, you need to be able to mock the response that comes back from the API request. Therefore you need to specify in the test what JSON (for example) would come back from the HTTP client. To do this in Zend Framework 2, you need to mock the Zend\Http\Client so that it always returns a mock response, and have the mock Zend\Http\Response always return the JSON...

Install ZeroMQ on Mac with PHP PECL extension

Getting ZeroMQ working on a Mac looks like a pain if you try to compile, but there’s a much easier way to get it up and running, with just a few brew and PECL commands. I’ve been wary of Homebrew for a while, as there were lots of issues with Macports in the past, but I’ve found it’s a lot easier than trying to compile various things yourself in OS X (I tried to compile...

Create diff patch from Composer /vendor to apply to Git repository

If you’ve accidentally made changes to a package in the /vendor directory of your project, you’ll need to apply these same changes to the Git repository that the package comes from (or fork it and patch it, etc.) before Composer overwrites the updates. The easiest way to do this is to create a diff patch which you can then apply to the package repository. You need to make sure...

Late Static Binding namespace resolution in PHP

If you try to get the namespace of the child class that you are in using the __NAMESPACE__ keyword, you will have the same problem that you do using functions like get_class() in that you will get the namespace (or class) where the current method you are calling is defined. $namespace = __NAMESPACE__; $class = get_class(); You can use get_called_class() to resolve this for Late Static Binding...