Need help with Mosquitto-PHP?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

471 Stars 126 Forks BSD 3-Clause "New" or "Revised" License 257 Commits 49 Opened issues


A wrapper for the Eclipse Mosquitto™ MQTT client library for PHP.

Services available


Need anything else?

Contributors list


This is an extension to allow using the Eclipse Mosquitto™ MQTT client library with PHP. See the

directory for usage.

Build Status

PHP 7 support

Thanks to Sara Golemon this extension now supports PHP 7. I would be grateful if anyone using PHP 7 could test it and let me know how it works out.


  • PHP 5.3+
  • libmosquitto 1.2.x or later
  • Linux or Mac OS X. I do not have a Windows machine handy, though patches or pull requests are of course very welcome!


If you've used a pre-built package to install Mosquitto, you need to make sure you have the development headers installed. On Red Hat-derived systems, this is probably called

, and on Debian-based systems it will be

You may obtain this package using PECL:

pecl install Mosquitto-alpha

Alternatively, you can use the normal extension build process:

./configure --with-mosquitto=/path/to/libmosquitto
make install

Then add
to your


argument is optional, and only required if your libmosquitto install cannot be found.

General operation

The underlying library is based on callbacks and asynchronous operation. As such, you have to call the

method of the
frequently to permit the library to handle the messages in its queues. Also, you should use the callback functions to ensure that you only attempt to publish after the client has connected, etc. For example, here is how you would correctly publish a QoS=2 message:
$mid = 0;
$c = new Mosquitto\Client("PHP");
$c->onConnect(function() use ($c, &$mid) {
    $mid = $c->publish("mgdm/test", "Hello", 2);

$c->onPublish(function($publishedId) use ($c, $mid) { if ($publishedId == $mid) { $c->disconnect(); } });

$c->connect("localhost"); $c->loopForever();

echo "Finished"


Full documentation is available on ReadTheDocs.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.