{"id":27962826,"url":"https://github.com/php-mqtt/laravel-client","last_synced_at":"2025-10-17T09:08:11.805Z","repository":{"id":41164294,"uuid":"208612516","full_name":"php-mqtt/laravel-client","owner":"php-mqtt","description":"An MQTT client library for Laravel.","archived":false,"fork":false,"pushed_at":"2025-03-31T03:55:29.000Z","size":51,"stargazers_count":200,"open_issues_count":2,"forks_count":21,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-07T19:57:27.206Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-mqtt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-15T15:13:48.000Z","updated_at":"2025-04-29T11:17:58.000Z","dependencies_parsed_at":"2024-01-22T06:24:00.663Z","dependency_job_id":"7f1a3865-26f2-4591-80e1-9c5d758b236f","html_url":"https://github.com/php-mqtt/laravel-client","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mqtt%2Flaravel-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mqtt%2Flaravel-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mqtt%2Flaravel-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mqtt%2Flaravel-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-mqtt","download_url":"https://codeload.github.com/php-mqtt/laravel-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346624,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-07T19:57:23.758Z","updated_at":"2025-10-17T09:08:11.701Z","avatar_url":"https://github.com/php-mqtt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-mqtt/laravel-client\n\n[![Latest Stable Version](https://poser.pugx.org/php-mqtt/laravel-client/v)](https://packagist.org/packages/php-mqtt/laravel-client)\n[![Total Downloads](https://poser.pugx.org/php-mqtt/laravel-client/downloads)](https://packagist.org/packages/php-mqtt/laravel-client)\n[![Tests](https://github.com/php-mqtt/laravel-client/workflows/Tests/badge.svg)](https://github.com/php-mqtt/laravel-client/actions?query=workflow%3ATests)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=php-mqtt_laravel-client\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)\n[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=php-mqtt_laravel-client\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)\n[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=php-mqtt_laravel-client\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)\n[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=php-mqtt_laravel-client\u0026metric=security_rating)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)\n[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=php-mqtt_laravel-client\u0026metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=php-mqtt_laravel-client)\n[![License](https://poser.pugx.org/php-mqtt/laravel-client/license)](https://packagist.org/packages/php-mqtt/laravel-client)\n\n`php-mqtt/laravel-client` was created by, and is maintained by [Marvin Mall](https://github.com/namoshek).\nIt is a Laravel wrapper for the [`php-mqtt/client`](https://github.com/php-mqtt/client) package and\nallows you to connect to an MQTT broker where you can publish messages and subscribe to topics.\n\n## Installation\n\nThe package is available on [packagist.org](https://packagist.org/packages/php-mqtt/laravel-client) and can be installed using composer:\n\n```bash\ncomposer require php-mqtt/laravel-client\n```\n\nThe package will register itself through Laravel auto discovery of packages.\nRegistered will be the service provider as well as an `MQTT` facade.\n\nAfter installing the package, you should publish the configuration file using\n\n```bash\nphp artisan vendor:publish --provider=\"PhpMqtt\\Client\\MqttClientServiceProvider\" --tag=\"config\"\n```\n\nand change the configuration in `config/mqtt-client.php` according to your needs.\n\n## Configuration\n\nThe package allows you to configure multiple named connections. An initial example with inline documentation can be found in the published configuration file.\nMost of the configuration options are optional and come with sane defaults (especially all of the `connection_settings`).\n\nAn example configuration of two connections, where one is meant for sharing public data and one for private data, could look like the following:\n```php\n'default_connection' =\u003e 'private',\n\n'connections' =\u003e [\n    'private' =\u003e [\n        'host' =\u003e 'mqtt.example.com',\n        'port' =\u003e 1883,\n    ],\n    'public' =\u003e [\n        'host' =\u003e 'test.mosquitto.org',\n        'port' =\u003e 1883,\n    ],\n],\n```\nIn this example, the private connection is the default one.\n\n_Note: it is recommended to use environment variables to configure the MQTT client. Available environment variables can be found in the configuration file._\n\n## Usage\n\n### Publish (QoS level 0)\n\nPublishing a message with QoS level 0 is quite easy and can be done in a single command:\n```php\nuse PhpMqtt\\Client\\Facades\\MQTT;\n\nMQTT::publish('some/topic', 'Hello World!');\n```\n\nIf needed, the _retain_ flag (default: `false`) can be passed as third and the connection name as fourth parameter:\n```php\nuse PhpMqtt\\Client\\Facades\\MQTT;\n\nMQTT::publish('some/topic', 'Hello World!', true, 'public');\n```\n\nUsing `MQTT::publish($topic, $message)` will implicitly call `MQTT::connection()`, but the connection will not be closed after usage.\nIf you want to close the connection manually because your script does not need the connection anymore,\nyou can call `MQTT:disconnect()` (optionally with the connection name as a parameter).\nPlease also note that using `MQTT::publish($topic, $message)` will always use QoS level 0.\nIf you need a different QoS level, you will need to use the `MqttClient` directly which is explained below.\n\n### Publish (QoS level 1 \u0026 2)\n\nDifferent to QoS level 0, we need to run an event loop in order for QoS 1 and 2 to work.\nThis is because with a one-off command we cannot guarantee that a message reaches its target.\nThe event loop will ensure a published message gets sent again if no acknowledgment is returned by the broker within a grace period.\nOnly when the broker returns an acknowledgement (or all of the acknowledgements in case of QoS 2),\nthe client will stop resending the message.\n\n```php\nuse PhpMqtt\\Client\\Facades\\MQTT;\n\n/** @var \\PhpMqtt\\Client\\Contracts\\MqttClient $mqtt */\n$mqtt = MQTT::connection();\n$mqtt-\u003epublish('some/topic', 'foo', 1);\n$mqtt-\u003epublish('some/other/topic', 'bar', 2, true); // Retain the message\n$mqtt-\u003eloop(true);\n```\n\n`$mqtt-\u003eloop()` actually starts an infinite loop. To escape it, there are multiple options.\nIn case of simply publishing a message, all we want is to receive an acknowledgement.\nTherefore, we can simply pass `true` as second parameter to exit the loop as soon as all resend queues are cleared:\n\n```php\n/** @var \\PhpMqtt\\Client\\Contracts\\MqttClient $mqtt */\n$mqtt-\u003eloop(true, true);\n```\n\nIn order to escape the loop, you can also call `$mqtt-\u003einterrupt()` which will exit the loop during\nthe next iteration. The method can, for example, be called in a registered signal handler:\n```php\n/** @var \\PhpMqtt\\Client\\Contracts\\MqttClient $mqtt */\npcntl_signal(SIGINT, function () use ($mqtt) {\n    $mqtt-\u003einterrupt();\n});\n```\n\n### Subscribe\n\nVery similar to publishing with QoS level 1 and 2, subscribing requires to run an event loop.\nAlthough before running the loop, topics need to be subscribed to:\n\n```php\nuse PhpMqtt\\Client\\Facades\\MQTT;\n\n/** @var \\PhpMqtt\\Client\\Contracts\\MqttClient $mqtt */\n$mqtt = MQTT::connection();\n$mqtt-\u003esubscribe('some/topic', function (string $topic, string $message) {\n    echo sprintf('Received QoS level 1 message on topic [%s]: %s', $topic, $message);\n}, 1);\n$mqtt-\u003eloop(true);\n```\n\n## Features\n\nThis library allows you to use all the features provided by [`php-mqtt/client`](https://github.com/php-mqtt/client).\nSimply retrieve an instance of `\\PhpMqtt\\Client\\Contracts\\MqttClient` with `MQTT::connection(string $name = null)` and use it directly.\n\nFor an extensive collection of examples which explain how to use the MQTT client (directly),\nyou can visit the [`php-mqtt/client-examples` repository](https://github.com/php-mqtt/client-examples).\n\n## License\n\n`php-mqtt/laravel-client` is open-source software licensed under the [MIT license](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-mqtt%2Flaravel-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-mqtt%2Flaravel-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-mqtt%2Flaravel-client/lists"}