PHPackages                             kokx/mqtt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kokx/mqtt

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kokx/mqtt
=========

MQTT Client library for PHP

0.1.0(6y ago)111MITPHP

Since Jul 1Pushed 6y agoCompare

[ Source](https://github.com/kokx/php-mqtt)[ Packagist](https://packagist.org/packages/kokx/mqtt)[ RSS](/packages/kokx-mqtt/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

A client implementation for the MQTT protocol version 3.1.1.

Installation
============

[](#installation)

To install, use `composer`:

```
composer require kokx/mqtt
```

Usage
=====

[](#usage)

To use php-mqtt, create an instance of the `MQTT\Client` class with a hostname and call `connect()` to connect to the the broker. Now you can `subscribe()` to topics and `publish()` messages to the broker.

Note that the client is non-blocking. You could publish messages with QoS 0 and then immediately break the connection, but any scenario where you would need blocking behavior will not work.

To ensure that messages are received and that the connection keeps open, you need to repeatedly call `loop()`. To ensure that the connection stays open without sudden reconnects, the keepalive time (32 seconds by default) should be at least 3 times the interval between calls to `loop()`. But it is recommended to call `loop()` more often for swift passing of messages on subscribed topics.

For more complete usage instructions, look at the documentation in [docs/usage.md](docs/usage.md).

Example
-------

[](#example)

```
