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)0575MITPHPCI passing

Since Feb 20Pushed 1y 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 1mo ago

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
- Composer (for managing dependencies)
- 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

29

—

LowBetter than 59% of packages

Maintenance44

Moderate activity, may be stable

Popularity15

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

441d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c012dfcb5cfe4fc75050de1e6bda705ed7d2013ea3031b8bef33c65c3fb1e8e?d=identicon)[hakhant21](/maintainers/hakhant21)

---

Top Contributors

[![hakhant21](https://avatars.githubusercontent.com/u/58629946?v=4)](https://github.com/hakhant21 "hakhant21 (1 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

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

20917.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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