{"id":21650201,"url":"https://github.com/alexmorbo/react-mqtt","last_synced_at":"2025-04-11T20:12:11.762Z","repository":{"id":56944691,"uuid":"207928663","full_name":"alexmorbo/react-mqtt","owner":"alexmorbo","description":"PHP asynchronous mqtt library","archived":false,"fork":false,"pushed_at":"2023-01-12T14:30:50.000Z","size":30,"stargazers_count":11,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T20:12:05.893Z","etag":null,"topics":["iot","mqtt","mqtt-client","php","reactphp"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexmorbo.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}},"created_at":"2019-09-12T00:08:51.000Z","updated_at":"2024-05-20T10:15:53.000Z","dependencies_parsed_at":"2023-02-09T12:15:44.151Z","dependency_job_id":null,"html_url":"https://github.com/alexmorbo/react-mqtt","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmorbo%2Freact-mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmorbo%2Freact-mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmorbo%2Freact-mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmorbo%2Freact-mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexmorbo","download_url":"https://codeload.github.com/alexmorbo/react-mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248473129,"owners_count":21109628,"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":["iot","mqtt","mqtt-client","php","reactphp"],"created_at":"2024-11-25T07:38:55.645Z","updated_at":"2025-04-11T20:12:11.740Z","avatar_url":"https://github.com/alexmorbo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ReactPHP MQTT Client\n\n**react-mqtt** is an MQTT client library for PHP.\n\nIts based on the reactPHP socket-client and added the MQTT protocol\nspecific functions.\nAlso based on https://github.com/oliverlorenz/phpMqttClient\n\n## Goal\n\nGoal of this project is easy to use MQTT client for PHP in a modern architecture without using any php modules.\nCurrently, only protocol version 4 (mqtt 3.1.1) is implemented.\n* Protocol specifications: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/csprd02/mqtt-v3.1.1-csprd02.html\n\n## Example library initial\n```php\n// mqtt.php\n\nuse Morbo\\React\\Mqtt\\Client;\nuse Morbo\\React\\Mqtt\\ConnectionOptions;\nuse Morbo\\React\\Mqtt\\Protocols\\Version4;\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n// Creating Event Loop\n$loop = React\\EventLoop\\Factory::create();\n\n// Connection configuration\n$config = [\n    'host' =\u003e 'localhost',\n    'port' =\u003e 1883,\n//    'options' =\u003e new ConnectionOptions([\n//        'username' =\u003e 'auth_user',\n//        'password' =\u003e 'auth_password',\n//        'clientId' =\u003e 'react_client', // default is 'react-'.uniqid()\n//        'cleanSession' =\u003e true, // default is true\n//        'cleanSession' =\u003e true, // default is true\n// .      'willTopic' =\u003e '',\n// .      'willMessage' =\u003e '',\n// .      'willQos' =\u003e '',\n// .      'willRetain' =\u003e '',\n// .      'keepAlive' =\u003e 60, // default is 60\n//    ])\n];\n\n$mqtt = new Client($loop, new Version4());\n\n```\n\n\n## Example publish\n\n```php\nuse React\\Socket\\ConnectionInterface;\n\nrequire 'mqtt.php';\n\n$connection = $mqtt-\u003econnect($config['host'], $config['port'], $config['options']);\n\n$connection-\u003ethen(function (ConnectionInterface $stream) use ($mqtt, $loop) {\n    /**\n     * Stop loop, when client disconnected from mqtt server\n     */\n    $stream-\u003eon('end', function () use ($loop) {\n        $loop-\u003estop();\n    });\n\n    $data = [\n        'foo' =\u003e 'bar',\n        'bar' =\u003e 'baz',\n        'time' =\u003e time(),\n    ];\n\n    $qos = Morbo\\React\\Mqtt\\Packets\\QoS\\Levels::AT_MOST_ONCE_DELIVERY;  // 0\n\n    $mqtt-\u003epublish($stream, 'foo/bar', json_encode($data), $qos)-\u003ethen(function (ConnectionInterface $stream) use ($mqtt) {\n        /**\n         * Disconnect when published\n         */\n        $mqtt-\u003edisconnect($stream);\n    });\n});\n\n\n$loop-\u003erun();\n```\n\n## Example subscribe\n\n\n```php\nuse Morbo\\React\\Mqtt\\Packets;\nuse React\\Socket\\ConnectionInterface;\n\nrequire 'mqtt.php';\n\n$connection = $mqtt-\u003econnect($config['host'], $config['port'], $config['options']);\n\n$connection-\u003ethen(function (ConnectionInterface $stream) use ($mqtt) {\n    $qos = Morbo\\React\\Mqtt\\Packets\\QoS\\Levels::AT_MOST_ONCE_DELIVERY;  // 0\n    $mqtt-\u003esubscribe($stream, 'foo/bar', $qos)-\u003ethen(function (ConnectionInterface $stream) use ($qos) {\n        // Success subscription\n        $stream-\u003eon(Packets\\Publish::EVENT, function(Packets\\Publish $publish) {\n            var_dump($publish);\n        });\n    }, function ($error) {\n        // Subscription error\n    });\n});\n\n$loop-\u003erun();\n```\n\n## Avaiable methods\nCurrently works:\n* connect (clean session, will options, keepalive, connection authorization)\n* disconnect\n* publish\n* subscribe","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmorbo%2Freact-mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexmorbo%2Freact-mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmorbo%2Freact-mqtt/lists"}