PHP Google Static Maps

A few years ago I created a wrapper for the Google Static Map API, it never received much fanfare, but it was a fun little project and it was functional. During my last holiday I found a little time to bring the whole thing more inline with what I've learnt So with that, it's been updated and now makes use of: PHP7 syntax Friends of PHP-CS-Fixer PSR-4 Auto-loading PHPUnit tests TravisCI testing/badges »

php-amqplib vs PHP AMQP Extension

##The Problem While testing Futureproofs API performance using BlackFire I noticed that we had a bottleneck centred around an fgets method. It wasn't part of our code (vague I know, I've lost the reference). After a bit of digging I found the culprit in the php-amqlib library; a library we use quite extensively from our API to add messages to RabbitMQ. Now php-amqlib is a great library, we've used it a lot and its never once let us down. »

PHP and Upstart

Up until recently I'd been using cron jobs to “kickstart” any failed/exited rabbitMQ consumers. It works, but didn't come without its own problems, for example: Cron jobs can be no more granular than 1 minute intervals, so if a cron fails, its could take up-to a minute to restart. There is no simple way to terminate/start or restart a process. So I did a bit of googling, I wanted something similar to forever. »

PHP & RabbitMQ Consumer 101 - Part 1

Over at FutureProofs we are in the process of converting one of our existing PDF intensive operations into a process which is triggered by a RabbitMQ consumer. RabbitMQ for those uninitialised is, put simply, a queueing system. You push “messages” onto it and then build consumers to take messages off again. Why would you do this? Why not have a cron job run these? Or simply trigger a process and let the user wait until it finishes? »

Futureproofs API Optimisation

In an attempt to increase the speed of the Futureproofs API, we made several tweaks to the environment and the code, below is a summary of the ones I can remember. Installed Profile Tools I've used xdebug for many years, its comprehensive, but quite resource intensive. A few years ago facebook released xhprof, which is a PHP profiler designed to run on live systems (its uses very little resource). Unlike xdebug and cachegrind XHProf doesn't run across all code automatically, you ‘start’ timing and ‘end’ timing by calling custom functions included in the PECL library. »

errmsg unauthorized when using PHP, mongoDB and mongoLabs.

While creating a DB migration script, we stumbled into a problem where commands using the PHP Mongo command “execute", ironically weren't being executed. The very short response message from the command read: 'errmsg' => 'unauthorized' After much googling, a none accepted answer in this stackoverflow link suggested that “certain” versions of the PHP mongo command request authorisation against the admin DB (which I don't have as I'm using mongoLabs). »

JS Splice Vs PHP Unset

This one cost me more time then I care to admit. Unknown to me at the time, Javascripts splice command reindexes the array it returns, PHP on the other hand doesn't. To replicate the same functionality in PHP simply call “array_values” and it will return your reindexed array. JS groups.splice(removePosition, 1); PHP unset($groups[$removePosition]); $groups = array_values($groups); »

Ben Squire on #php, #js,

SVGs to PNGs (with transparency) using PHPs Imagemagick library

While working on a project for work, it became necessary to generate a series of images which would be stamped onto a PDF page. Our php/pdf solution only supports raster images (JPEGs/PNGs etc) while our stamps were SVGs. This handy snippet of code converts an SVG into a PNG using imagemagick but with a transparent background colour. <?php $im = new Imagick(); $im->setBackgroundColor(new ImagickPixel('transparent')); $svg = file_get_contents("path/to/svg.svg"); $im->readImageBlob($svg); $im->setImageFormat("png32"); $im->imageWriteFile("path/to/save/svg.png"); »

Ben Squire on #php,

pecl install mongo - not a valid package archive

On June 23rd 2014 @ 9:30am GMT, while trying to ‘vagrant up’ a development environment at work, I was getting messages of failed dependencies when installing mongo. A quick SSH onto the box and the following output was revealed. sudo pecl install mongo downloading mongo-1.5.4.tgz ... Starting to download mongo-1.5.4.tgz (Unknown size) ....done: 3,582 bytes Could not get contents of package "/build/buildd/php5-5.3.10/pear-build-download/mongo-1.5.4.tgz". Invalid tgz file. Download of "pecl/mongo" succeeded, but it is not a valid package archive Error: cannot download "pecl/mongo" Download failed install failed Further googling revealed similar issues, others suggested the problem with certain 32bit versions of PHP. »

pecl install mongo - not a valid package archive

On June 23rd 2014 @ 9:30am GMT, while trying to ‘vagrant up’ a development environment at work, I was getting messages of failed dependencies when installing mongo. A quick SSH onto the box and the following output was revealed. sudo pecl install mongo downloading mongo-1.5.4.tgz ... Starting to download mongo-1.5.4.tgz (Unknown size) ....done: 3,582 bytes Could not get contents of package "/build/buildd/php5-5.3.10/pear-build-download/mongo-1.5.4.tgz". Invalid tgz file. Download of "pecl/mongo" succeeded, but it is not a valid package archive Error: cannot download "pecl/mongo" Download failed install failed Further googling revealed similar issues, others suggested the problem with certain 32bit versions of PHP. »