{"id":16405552,"url":"https://github.com/walkor/mqtt","last_synced_at":"2025-05-15T09:06:22.791Z","repository":{"id":45128868,"uuid":"137325659","full_name":"walkor/mqtt","owner":"walkor","description":"Asynchronous MQTT client for PHP based on workerman.","archived":false,"fork":false,"pushed_at":"2025-05-07T15:00:58.000Z","size":108,"stargazers_count":210,"open_issues_count":4,"forks_count":48,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-07T16:20:00.259Z","etag":null,"topics":["mqtt","mqtt-client","php-mqtt"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/walkor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-06-14T07:58:56.000Z","updated_at":"2025-05-07T15:00:15.000Z","dependencies_parsed_at":"2024-11-06T05:33:14.203Z","dependency_job_id":"428c8b79-27aa-409f-abd4-d9a13347cedb","html_url":"https://github.com/walkor/mqtt","commit_stats":{"total_commits":60,"total_committers":8,"mean_commits":7.5,"dds":"0.19999999999999996","last_synced_commit":"e19f9de02732d412a2f3fd1cf9a06cdaf5187f24"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walkor%2Fmqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walkor%2Fmqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walkor%2Fmqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walkor%2Fmqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/walkor","download_url":"https://codeload.github.com/walkor/mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254001574,"owners_count":21997596,"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":["mqtt","mqtt-client","php-mqtt"],"created_at":"2024-10-11T06:06:16.744Z","updated_at":"2025-05-15T09:06:22.767Z","avatar_url":"https://github.com/walkor.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MQTT\nAsynchronous MQTT client for PHP based on workerman.\n\n# Installation\n```bash\ncomposer require workerman/mqtt\n```\n\n# 文档\n[中文文档](https://www.workerman.net/doc/workerman/components/workerman-mqtt.html)\n\n# support\n\n- MQTT\n- MQTT 5\n- MQTT over websocket\n\n# Example\n**subscribe.php**\n```php\n\u003c?php\nrequire __DIR__ . '/vendor/autoload.php';\nuse Workerman\\Worker;\n$worker = new Worker();\n$worker-\u003eonWorkerStart = function(){\n    $mqtt = new Workerman\\Mqtt\\Client('mqtt://test.mosquitto.org:1883');\n    $mqtt-\u003eonConnect = function($mqtt) {\n        $mqtt-\u003esubscribe('test');\n    };\n    $mqtt-\u003eonMessage = function($topic, $content){\n        var_dump($topic, $content);\n    };\n    $mqtt-\u003econnect();\n};\nWorker::runAll();\n```\nRun with command ```php subscribe.php start```\n\n**publish.php**\n```php\n\u003c?php\nrequire __DIR__ . '/vendor/autoload.php';\nuse Workerman\\Worker;\n$worker = new Worker();\n$worker-\u003eonWorkerStart = function(){\n    $mqtt = new Workerman\\Mqtt\\Client('mqtt://test.mosquitto.org:1883');\n    $mqtt-\u003eonConnect = function($mqtt) {\n       $mqtt-\u003epublish('test', 'hello workerman mqtt');\n    };\n    $mqtt-\u003econnect();\n};\nWorker::runAll();\n```\n\nRun with command ```php publish.php start```\n\n## API\n\n  * \u003ca href=\"#construct\"\u003e\u003ccode\u003eClient::\u003cb\u003e__construct()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#connect\"\u003e\u003ccode\u003eClient::\u003cb\u003econnect()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#publish\"\u003e\u003ccode\u003eClient::\u003cb\u003epublish()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#subscribe\"\u003e\u003ccode\u003eClient::\u003cb\u003esubscribe()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#unsubscribe\"\u003e\u003ccode\u003eClient::\u003cb\u003eunsubscribe()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#disconnect\"\u003e\u003ccode\u003eClient::\u003cb\u003edisconnect()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#close\"\u003e\u003ccode\u003eClient::\u003cb\u003eclose()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#onConnect\"\u003e\u003ccode\u003ecallback \u003cb\u003eonConnect\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#onMessage\"\u003e\u003ccode\u003ecallback \u003cb\u003eonMessage\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#onError\"\u003e\u003ccode\u003ecallback \u003cb\u003eonError\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#onClose\"\u003e\u003ccode\u003ecallback \u003cb\u003eonClose\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n\n-------------------------------------------------------\n\n\u003ca name=\"construct\"\u003e\u003c/a\u003e\n### __construct (string $address, [array $options])\n\nCreate an instance by $address and $options.\n\n  * `$address` can be on the following protocols: 'mqtt', 'mqtts', 'mqtt://test.mosquitto.org:1883'. \n\n  * `$options` is the client connection options. Defaults:\n    * `keepalive`: `50` seconds, set to `0` to disable\n    * `client_id`: client id, default `workerman-mqtt-client-{$mt_rand}`\n    * `protocol_name`: `'MQTT'` or '`MQIsdp`'\n    * `protocol_level`: `'MQTT'` is `4` and '`MQIsdp`' is `3`\n    * `clean_session`: `true`, set to false to receive QoS 1 and 2 messages while\n      offline\n    * `reconnect_period`: `1` second, interval between two reconnections\n    * `connect_timeout`: `30` senconds, time to wait before a CONNACK is received\n    * `username`: the username required by your broker, if any\n    * `password`: the password required by your broker, if any\n    * `will`: a message that will sent by the broker automatically when\n       the client disconnect badly. The format is:\n      * `topic`: the topic to publish\n      * `content`: the message to publish\n      * `qos`: the QoS\n      * `retain`: the retain flag\n    * `resubscribe` : if connection is broken and reconnects,\n       subscribed topics are automatically subscribed again (default `true`)\n    * `bindto` default '', used to specify the IP address that PHP will use to access the network\n    * `ssl` default `false`, it can be set `true` or `ssl context` see http://php.net/manual/en/context.ssl.php\n    * `debug` default `false`, set `true` to show debug info\n\n-------------------------------------------------------\n\n\u003ca name=\"connect\"\u003e\u003c/a\u003e\n### connect()\n\nConnect to broker specified by the given $address and $options in `__construct($address, $options)`.\n\n-------------------------------------------------------\n\n\u003ca name=\"publish\"\u003e\u003c/a\u003e\n### publish(String $topic, String $content, [array $options], [callable $callback], [array $properties])\n\nPublish a message to a topic\n\n* `$topic` is the topic to publish to, `String`\n* `$message` is the message to publish, `String`\n* `$options` is the options to publish with, including:\n  * `qos` QoS level, `Number`, default `0`\n  * `retain` retain flag, `Boolean`, default `false`\n  * `dup` mark as duplicate flag, `Boolean`, default `false`\n* `$callback` - `function (\\Exception $exception)`, fired when the QoS handling completes, or at the next tick if QoS 0. No error occurs then `$exception` will be null.\n* `$properties` - `array` MQTT5 user properties\n  \n  \n-------------------------------------------------------\n\n\u003ca name=\"subscribe\"\u003e\u003c/a\u003e\n### subscribe(mixed $topic, [array $options], [callable $callback], [array $properties])\n\nSubscribe to a topic or topics\n\n* `$topic` is a `String` topic or an `Array` which has as keys the topic name and as value\nthe QoS like `array('test1'=\u003e 0, 'test2'=\u003e 1)` to subscribe.\n* `$options` is the options to subscribe with, including:\n  * `qos` qos subscription level, default 0\n* `$callback` - `function (\\Exception $exception, array $granted)`\n  callback fired on suback where:\n  * `exception` a subscription error or an error that occurs when client is disconnecting\n  * `granted` is an array of `array('topic' =\u003e 'qos', 'topic' =\u003e 'qos')` where:\n    * `topic` is a subscribed to topic\n    * `qos` is the granted qos level on it\n* `$properties` - `array` MQTT5 user properties\n\n-------------------------------------------------------\n\n\u003ca name=\"unsubscribe\"\u003e\u003c/a\u003e\n### unsubscribe(mixed $topic, [callable $callback], [array $properties])\n\nUnsubscribe from a topic or topics\n\n* `$topic` is a `String` topic or an array of topics to unsubscribe from\n* `$callback` - `function (\\Exception $e)`, fired on unsuback. No error occurs then `$exception` will be null..\n* `$properties` - `array` MQTT5 user properties\n\n-------------------------------------------------------\n\n\u003ca name=\"disconnect\"\u003e\u003c/a\u003e\n### disconnect()\n\nSend DISCONNECT package to broker and close the client.\n\n-------------------------------------------------------\n\n\u003ca name=\"close\"\u003e\u003c/a\u003e\n### close()\n\nClose the client without DISCONNECT package.\n\n-------------------------------------------------------\n\n\u003ca name=\"onConnect\"\u003e\u003c/a\u003e\n### callback onConnect(Client $mqtt)\nEmitted on successful connection (`CONNACK` package received).\n\n-------------------------------------------------------\n\n\u003ca name=\"onMessage\"\u003e\u003c/a\u003e\n### callback onMessage(String $topic, String $content, Client $mqtt, array $properties)\n`function (topic, message, client, properties) {}`\n\nEmitted when the client receives a publish packet\n* `$topic` topic of the received packet\n* `$content` payload of the received packet\n* `$mqtt` Client instance.\n* `$properties` `array` MQTT5 user properties\n\n-------------------------------------------------------\n\n\u003ca name=\"onError\"\u003e\u003c/a\u003e\n### callback onError(\\Exception $exception)\nEmitted when something wrong for example the client cannot connect broker.\n\n-------------------------------------------------------\n\n\u003ca name=\"onClose\"\u003e\u003c/a\u003e\n### callback onClose()\nEmitted when connection closed.\n\n-------------------------------------------------------\n\n\n# License\n\nMIT\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwalkor%2Fmqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwalkor%2Fmqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwalkor%2Fmqtt/lists"}