PHPackages                             karpy47/php-mqtt-client - 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. karpy47/php-mqtt-client

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

karpy47/php-mqtt-client
=======================

MQTT 3.1.1 library for PHP with TLS support

v1.0.4(6y ago)3888.3k↑35.1%191MITPHP

Since Aug 9Pushed 3y ago7 watchersCompare

[ Source](https://github.com/karpy47/PhpMqttClient)[ Packagist](https://packagist.org/packages/karpy47/php-mqtt-client)[ RSS](/packages/karpy47-php-mqtt-client/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (4)DependenciesVersions (4)Used By (1)

PhPMqttClient
=============

[](#phpmqttclient)

MQTT 3.1.1 Client with TSL support in PHP

Note that all calls are blocking until a timeout occurs. If you need some fancy async solution, you'll have to find another repo.

This implementation works with [MQTT ver 3.1.1](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html) for QOS levels 0 and 1. QOS level 2 should work, but is experimental until better tested.

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist karpy47/php-mqtt-client

```

or add

```
"karpy47/php-mqtt-client": "*"

```

to the require section of your composer.json.

Requirements
============

[](#requirements)

Should work with all recent PHP versions.

Code developed and running in production using PHP v7.0.27 (previously also PHP v5.6.27)

Basic Usage
===========

[](#basic-usage)

```
use karpy47\PhpMqttClient\MQTTClient;

$client = new MQTTClient('mqtt-server.domain.com', 8162);
$client->setAuthentication('mqtt-server.username','mqtt-server.password');
$client->setEncryption('cacerts.pem');
$success = $client->sendConnect(12345);  // set your client ID
if ($success) {
    $client->sendSubscribe('topic1');
    $client->sendPublish('topic2', 'Message to all subscribers of this topic');
    $messages = $client->getPublishMessages();  // now read and acknowledge all messages waiting
    foreach ($messages as $message) {
        echo $message['topic'] .': '. $message['message'] . PHP_EOL;
        // Other keys in $message array: retain (boolean), duplicate (boolean), qos (0-2), packetId (2-byte integer)
    }
    $client->sendDisconnect();
}
$client->close();

```

Credits
=======

[](#credits)

Thanks to [bluerhinos/phpMQTT](https://github.com/bluerhinos/phpMQTT) and [McFizh/libMQTT](https://github.com/McFizh/libMQTT).

Also thanks to

- [pascalwacker](https://github.com/pascalwacker/php-mqtt-client) for forking and fixing some bugs
- [tobbexiv](https://github.com/tobbexiv) for finding and fixing several bugs

License
=======

[](#license)

Released under the MIT License. Please see [License File](LICENSE) for more information.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 74.1% 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 ~359 days

Total

3

Last Release

2521d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9e54e05dcadf29d16ea0314a551bfbc201e8cb48fb4fa83390cfa73273c60b3?d=identicon)[karpy47](/maintainers/karpy47)

---

Top Contributors

[![karpy47](https://avatars.githubusercontent.com/u/8948719?v=4)](https://github.com/karpy47 "karpy47 (43 commits)")[![tobbexiv](https://avatars.githubusercontent.com/u/5681598?v=4)](https://github.com/tobbexiv "tobbexiv (11 commits)")[![dpslwk](https://avatars.githubusercontent.com/u/234460?v=4)](https://github.com/dpslwk "dpslwk (3 commits)")[![trajche](https://avatars.githubusercontent.com/u/2382019?v=4)](https://github.com/trajche "trajche (1 commits)")

---

Tags

phpclientmqtt

### Embed Badge

![Health badge](/badges/karpy47-php-mqtt-client/health.svg)

```
[![Health](https://phpackages.com/badges/karpy47-php-mqtt-client/health.svg)](https://phpackages.com/packages/karpy47-php-mqtt-client)
```

###  Alternatives

[php-mqtt/laravel-client

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

226593.3k3](/packages/php-mqtt-laravel-client)[graze/telnet-client

Telnet client written in PHP

48242.5k4](/packages/graze-telnet-client)[ihsw/toxiproxy-php-client

PHP client for shopify/toxiproxy

313.4k4](/packages/ihsw-toxiproxy-php-client)[hyperf/mqtt-server-incubator

MQTT Server for Hyperf

172.6k](/packages/hyperf-mqtt-server-incubator)

PHPackages © 2026

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