PHPackages                             gunnar/mqttclient - 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. gunnar/mqttclient

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

gunnar/mqttclient
=================

php mqtt client

1.3(8y ago)26MITPHPPHP &gt;=5.6.0

Since Aug 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/oGre222/mqttclient)[ Packagist](https://packagist.org/packages/gunnar/mqttclient)[ RSS](/packages/gunnar-mqttclient/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

gunnar/mqttclient
=================

[](#gunnarmqttclient)

PHP mqtt client

usage
-----

[](#usage)

### Install

[](#install)

Install:

```
composer require gunnar/mqttclient

```

If your composer not allowed dev-master,add this config

```
"minimum-stability": "dev"

```

into your composer.json.

### Require

[](#require)

```
swoole 2.0.8+

```

### Example

[](#example)

define your logger:

```
class Logger implements \mqttclient\src\swoole\MqttLogInterface {

	public function log($type,$content,$params = []){
	        echo "$type : $content \r\n";
	 }
}

```

define your tmp store (use Redis/Memory/...)

```
class Store implements \mqttclient\src\swoole\TmpStorageInterface{

	private $data = [];

    public function set($message_type, $key, $sub_key, $data, $expire = 3600)
    {
        $this->data[$message_type][$key][$sub_key] = $data;
    }

    public function get($message_type, $key, $sub_key)
    {
        return $this->data[$message_type][$key][$sub_key];
    }

    public function delete($message_type, $key, $sub_key)
    {
        if (!isset($this->data[$message_type][$key][$sub_key])){
            echo "storage not found:$message_type $key $sub_key";
        }
        unset($this->data[$message_type][$key][$sub_key]);
    }

}

```

use MqttClient

```
$host = '127.0.0.1';
$port = 1883;

$r = new \mqttclient\src\swoole\MqttClient($host,$port,10017);
$r->setAuth('username','password');
$r->setKeepAlive(60);
$r->setLogger(new Logger());
$r->setStore(new Store());
$r->setTopics(
[
    new \mqttclient\src\subscribe\Topic('test/slim',function($msg){
        echo "I receive:".$msg."\r\n";}),
    new \mqttclient\src\subscribe\Topic('test/slim3',function(\mqttclient\src\swoole\MqttClient $client,$msg){
        echo "I receive:".$msg." for slim3 \r\n";
        echo $client->getClientId();
    })
]
);

//set trigger
$r->on(\mqttclient\src\consts\ClientTriggers::RECEIVE_SUBACK,function(\mqttclient\src\swoole\MqttClient $client){
	$client->publish('slim/echo','GGXX',\mqttclient\src\consts\Qos::ONE_TIME);
});

$r->connect();
$r->publish('test/slim','test qos',2);

```

### Extends

[](#extends)

You can also use own client extends MqttClient.

Example:

```
class Client extends MqttClient
{
    private $mysql_handler;
    private $mongo_handler;

    public function __construct($host,$port,$client_id,$mysql_conf,$mongo_conf)
    {
        $this->mysql_handler = new Mysqli($mysql_conf);
        $this->mongo_handler = new \MongoClient('mongodb://'.$mongo_conf['username'].':'.$mongo_conf['password'].'@'.$mongo_conf['host'].':'.$mongo_conf['port'].'/'.$mongo_conf['db']);
        parent::__construct($host,$port,$client_id);
    }

	 /**
     * override the produceContainer function and map your own class/data/closure to the injector,and they can be used in every publish receive handler
     * for exp: $client->setTopics([new Topic('test/own',function($mongo,$msg){ $result = $mongo->selectCollection('log_platform','test')->find(['sid' => ['$gte' => intval($msg)]]); })]);
     * @return Injector
     */
    protected function produceContainer()
    {
        $container = new Injector();
        $container->mapData(MqttClient::class,$this);
        $container->mapData(Client::class,$this);
        $container->mapData('mysqli',$this->mysql_handler);
        $container->mapData('mongo',$this->mongo_handler);
        return $container;
    }

}

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~40 days

Total

3

Last Release

3117d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a3a9fc48b385a1b3de94a3d70c72e37c726e2b50c85fa80296b6745f9602e07?d=identicon)[oGre222](/maintainers/oGre222)

---

Top Contributors

[![jesusslim](https://avatars.githubusercontent.com/u/12554966?v=4)](https://github.com/jesusslim "jesusslim (18 commits)")

---

Tags

mqtt

### Embed Badge

![Health badge](/badges/gunnar-mqttclient/health.svg)

```
[![Health](https://phpackages.com/badges/gunnar-mqttclient/health.svg)](https://phpackages.com/packages/gunnar-mqttclient)
```

###  Alternatives

[php-mqtt/laravel-client

A wrapper for the php-mqtt/client library for Laravel.

228539.3k1](/packages/php-mqtt-laravel-client)[binsoul/net-mqtt

MQTT protocol implementation

28897.8k7](/packages/binsoul-net-mqtt)

PHPackages © 2026

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