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

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

hakhant/mqtt-client
===================

An MQTT client written in and for PHP.

1.3.2(1y ago)0598MITPHPCI passing

Since Feb 20Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/hakhant21/mqtt-client)[ Packagist](https://packagist.org/packages/hakhant/mqtt-client)[ RSS](/packages/hakhant-mqtt-client/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (5)Versions (7)Used By (0)

Hakhant Laravel MQTT Client
===========================

[](#hakhant-laravel-mqtt-client)

This is a simple Laravel wrapper for interacting with MQTT brokers using the `PhpMqtt\Client` library. It provides an easy way to publish and subscribe to topics, and handle MQTT connections.

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- PhpMqtt\\Client library

Installation
------------

[](#installation)

To get started, you need to install the MQTT Client package via Composer:

```
composer require hakhant/mqtt-client
```

Create a configuration file for the MQTT client. Run the following artisan command to publish the configuration file:
---------------------------------------------------------------------------------------------------------------------

[](#create-a-configuration-file-for-the-mqtt-client-run-the-following-artisan-command-to-publish-the-configuration-file)

```
php artisan vendor:publish --provider="Hakhant\Broker\Providers\ClientServiceProvider" --tag="config"
```

This will create a config/mqtt.php file in your Laravel project where you can define the necessary configuration options for connecting to the MQTT broker.
-----------------------------------------------------------------------------------------------------------------------------------------------------------

[](#this-will-create-a-configmqttphp-file-in-your-laravel-project-where-you-can-define-the-necessary-configuration-options-for-connecting-to-the-mqtt-broker)

```
// config/mqtt.php
return [
    'host'     => env('MQTT_HOST', 'broker.hivemq.com'), // The MQTT broker host
    'port'     => env('MQTT_PORT', 1883),                // MQTT Broker port (default 1883)
    'username' => env('MQTT_USERNAME', ''),               // Optional: MQTT Username (if required)
    'password' => env('MQTT_PASSWORD', ''),               // Optional: MQTT Password (if required)
    'client_id'=> env('MQTT_CLIENT_ID', 'your-client-id'),// A unique client ID for the connection
    'keep_alive' => env('MQTT_KEEP_ALIVE', 60) // Keepalive interval ( default 60 )
];
```

Environment Configuration
-------------------------

[](#environment-configuration)

```
MQTT_HOST=127.0.0.1
MQTT_PORT=1883
MQTT_USERNAME=username
MQTT_PASSWORD=password
MQTT_CLIENT_ID=my-client-id
MQTT_KEEP_ALIVE=60
```

Usage
-----

[](#usage)

```
use Hakhant\Broker\Client;

class MqttController extends Controller
{
    protected $mqttClient;

    public function __construct(Client $mqttClient)
    {
        $this->mqttClient = $mqttClient;
    }

    public function publishMessage()
    {
        $topic = 'topic/test';
        $message = 'Hello from Laravel MQTT!';
        $qos = 0; // Quality of Service level
        $retain = false; // Whether the message should be retained

        // Publish message
        $this->mqttClient->publish($topic, $message, $qos, $retain);

        return response()->json(['status' => 'Message Published']);
    }

    public function subscribeToTopic()
    {
        $topic = 'topic/test';
        $this->mqttClient->subscribe($topic, function($topic, $message) {
            // Handle the received message
            echo "Message received on topic {$topic}: {$message}\n";
        });

        // Keep the loop running to listen for messages
        $this->mqttClient->loop()
    }
}
```

### Summary of Features:

[](#summary-of-features)

- **MQTT Client Service**: Easily integrate with Laravel using a service provider.
- **Environment Configuration**: Define broker settings in `.env` and `config/mqtt.php`.
- **Publish/Subscribe**: Methods to publish messages and subscribe to topics in your controllers.
- **Looping for Messages**: Keep the MQTT connection alive by running the loop in the background.

This should allow you to easily integrate MQTT into a Laravel application! Let me know if you need any further modifications.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance66

Regular maintenance activity

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

Total

6

Last Release

489d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/58629946?v=4)[Htet Aung Khant](/maintainers/hakhant21)[@hakhant21](https://github.com/hakhant21)

---

Top Contributors

[![hakhant21](https://avatars.githubusercontent.com/u/58629946?v=4)](https://github.com/hakhant21 "hakhant21 (2 commits)")

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M10](/packages/renatomarinho-laravel-page-speed)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/redis

The Illuminate Redis package.

8314.6M377](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

244.6M137](/packages/illuminate-cookie)

PHPackages © 2026

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