A new OSS PHP MQTT Client Library - phpMQTT

It seems finally we may be freed from the unstable shakiness which is embodied in PHP_SAM - the only PHP based MQTT client….until now.

Project SAM is a PHP library for several different pubsub messaging systems, one being MQTT. However it suffers from a very restrictive licence, a lack of maintenance and quite a few bugs. Previously there was no choice if you wished to use MQTT and PHP, now Andrew Milsted (@bluerhinos) has started to produce an alternative: phpMQTT

phpMQTT is only in infancy at the moment and currently only publishing is fully functional, with some bugs to be ironed out of subscriptions, however for anyone who has used PHP_SAM it provides a refreshingly easy way to start using MQTT - consisting of just one file and a handful of simple functions. An example of publishing a message (written by Andrew Milsted) is shown below:


$mqtt = new phpMQTT();

/* broker(broker address, broker port, client id); */
$mqtt->broker('example.com', 1883, 'PHP MQTT Client');

/* publish( topic, message, qos); */
$mqtt->publish('bluerhinos/phpMQTT/examples/publishtest','Hello World!',0);

The main point to note from this example is that unlike PHP_SAM I could just download the library and run it straight away, no looking through to see why it was causing errors, no patching to work with mosquitto, it just worked (all the bits that claimed to work anyway). It’s also simple enough that anyone with a basic grasp of any C style language and MQTT could start using straight away with any documentation!

The MQTT scene has seen quite an influx of interest of late and the OSS community is responding to this by producing an increasingly large range of associated software, phpMQTT being the latest in a series of projects driving MQTT away from being an niche IBM employee interest into a more widely known technology, this can only be good for all involved.