PHPackages                             alexmorbo/react-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. [HTTP &amp; Networking](/categories/http)
4. /
5. alexmorbo/react-mqtt

ActiveLibrary[HTTP &amp; Networking](/categories/http)

alexmorbo/react-mqtt
====================

Async MQTT client in reactphp

0.2(4y ago)122425[1 PRs](https://github.com/alexmorbo/react-mqtt/pulls)MITPHP

Since Sep 12Pushed 3y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

ReactPHP MQTT Client
====================

[](#reactphp-mqtt-client)

**react-mqtt** is an MQTT client library for PHP.

Its based on the reactPHP socket-client and added the MQTT protocol specific functions. Also based on

Goal
----

[](#goal)

Goal of this project is easy to use MQTT client for PHP in a modern architecture without using any php modules. Currently, only protocol version 4 (mqtt 3.1.1) is implemented.

- Protocol specifications:

Example library initial
-----------------------

[](#example-library-initial)

```
// mqtt.php

use Morbo\React\Mqtt\Client;
use Morbo\React\Mqtt\ConnectionOptions;
use Morbo\React\Mqtt\Protocols\Version4;

require_once __DIR__ . '/vendor/autoload.php';

// Creating Event Loop
$loop = React\EventLoop\Factory::create();

// Connection configuration
$config = [
    'host' => 'localhost',
    'port' => 1883,
//    'options' => new ConnectionOptions([
//        'username' => 'auth_user',
//        'password' => 'auth_password',
//        'clientId' => 'react_client', // default is 'react-'.uniqid()
//        'cleanSession' => true, // default is true
//        'cleanSession' => true, // default is true
// .      'willTopic' => '',
// .      'willMessage' => '',
// .      'willQos' => '',
// .      'willRetain' => '',
// .      'keepAlive' => 60, // default is 60
//    ])
];

$mqtt = new Client($loop, new Version4());
```

Example publish
---------------

[](#example-publish)

```
use React\Socket\ConnectionInterface;

require 'mqtt.php';

$connection = $mqtt->connect($config['host'], $config['port'], $config['options']);

$connection->then(function (ConnectionInterface $stream) use ($mqtt, $loop) {
    /**
     * Stop loop, when client disconnected from mqtt server
     */
    $stream->on('end', function () use ($loop) {
        $loop->stop();
    });

    $data = [
        'foo' => 'bar',
        'bar' => 'baz',
        'time' => time(),
    ];

    $qos = Morbo\React\Mqtt\Packets\QoS\Levels::AT_MOST_ONCE_DELIVERY;  // 0

    $mqtt->publish($stream, 'foo/bar', json_encode($data), $qos)->then(function (ConnectionInterface $stream) use ($mqtt) {
        /**
         * Disconnect when published
         */
        $mqtt->disconnect($stream);
    });
});

$loop->run();
```

Example subscribe
-----------------

[](#example-subscribe)

```
use Morbo\React\Mqtt\Packets;
use React\Socket\ConnectionInterface;

require 'mqtt.php';

$connection = $mqtt->connect($config['host'], $config['port'], $config['options']);

$connection->then(function (ConnectionInterface $stream) use ($mqtt) {
    $qos = Morbo\React\Mqtt\Packets\QoS\Levels::AT_MOST_ONCE_DELIVERY;  // 0
    $mqtt->subscribe($stream, 'foo/bar', $qos)->then(function (ConnectionInterface $stream) use ($qos) {
        // Success subscription
        $stream->on(Packets\Publish::EVENT, function(Packets\Publish $publish) {
            var_dump($publish);
        });
    }, function ($error) {
        // Subscription error
    });
});

$loop->run();
```

Avaiable methods
----------------

[](#avaiable-methods)

Currently works:

- connect (clean session, will options, keepalive, connection authorization)
- disconnect
- publish
- subscribe

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~895 days

Total

2

Last Release

1588d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/56429a05844186965705cb44ec8c40ca0826f278cb0dc90cdc11e8c214cbe8ce?d=identicon)[alexmorbo](/maintainers/alexmorbo)

---

Top Contributors

[![alexmorbo](https://avatars.githubusercontent.com/u/435562?v=4)](https://github.com/alexmorbo "alexmorbo (3 commits)")

---

Tags

iotmqttmqtt-clientphpreactphpiotmqtt

### Embed Badge

![Health badge](/badges/alexmorbo-react-mqtt/health.svg)

```
[![Health](https://phpackages.com/badges/alexmorbo-react-mqtt/health.svg)](https://phpackages.com/packages/alexmorbo-react-mqtt)
```

###  Alternatives

[symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k853.6M8.3k](/packages/symfony-http-kernel)[symfony/http-client

Provides powerful methods to fetch HTTP resources synchronously or asynchronously

2.0k338.8M4.6k](/packages/symfony-http-client)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[php-mqtt/client

An MQTT client written in and for PHP.

4402.3M35](/packages/php-mqtt-client)[api-platform/metadata

API Resource-oriented metadata attributes and factories

244.5M182](/packages/api-platform-metadata)[bitrix24/b24phpsdk

An official PHP library for the Bitrix24 REST API

10239.4k5](/packages/bitrix24-b24phpsdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
