{"id":16840294,"url":"https://github.com/mgdm/mosquitto-php","last_synced_at":"2025-04-04T12:08:34.406Z","repository":{"id":10761051,"uuid":"13023638","full_name":"mgdm/Mosquitto-PHP","owner":"mgdm","description":"A wrapper for the Eclipse Mosquitto™ MQTT client library for PHP.","archived":false,"fork":false,"pushed_at":"2023-10-03T14:27:01.000Z","size":259,"stargazers_count":531,"open_issues_count":51,"forks_count":147,"subscribers_count":62,"default_branch":"master","last_synced_at":"2024-10-14T12:36:01.249Z","etag":null,"topics":["libmosquitto","mosquitto","mqtt","mqtt-client","php"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mgdm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-09-23T00:40:11.000Z","updated_at":"2024-10-01T10:41:01.000Z","dependencies_parsed_at":"2022-07-14T01:40:32.165Z","dependency_job_id":"93ffa392-94cc-41ef-980c-a53d3b26e2e6","html_url":"https://github.com/mgdm/Mosquitto-PHP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgdm%2FMosquitto-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgdm%2FMosquitto-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgdm%2FMosquitto-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgdm%2FMosquitto-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgdm","download_url":"https://codeload.github.com/mgdm/Mosquitto-PHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174423,"owners_count":20896078,"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":["libmosquitto","mosquitto","mqtt","mqtt-client","php"],"created_at":"2024-10-13T12:36:07.219Z","updated_at":"2025-04-04T12:08:34.384Z","avatar_url":"https://github.com/mgdm.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mosquitto-PHP\n\nThis is an extension to allow using the [Eclipse Mosquitto™ MQTT client library](http://mosquitto.org) with PHP. See the `examples/` directory for usage.\n\n[![Build Status](https://travis-ci.org/mgdm/Mosquitto-PHP.svg?branch=master)](https://travis-ci.org/mgdm/Mosquitto-PHP)\n\n## PHP 7 support\n\nThanks to [Sara Golemon](https://twitter.com/SaraMG) this extension now supports PHP 7. I would be grateful if anyone using PHP 7 could test it and let me know how it works out.\n\n## Requirements\n\n* PHP 5.3+\n* libmosquitto 1.2.x or later\n* Linux or Mac OS X. I do not have a Windows machine handy, though patches or\n  pull requests are of course very welcome!\n\n## Installation\n\nIf you've used a pre-built package to install Mosquitto, you need to make sure you have the development headers installed. On Red Hat-derived systems, this is probably called `libmosquitto-devel`, and on Debian-based systems it will be `libmosquitto-dev`.\n\nYou may obtain this package using [PECL](http://pecl.php.net):\n\n````\npecl install Mosquitto-alpha\n````\n\nAlternatively, you can use the normal extension build process:\n\n````\nphpize\n./configure --with-mosquitto=/path/to/libmosquitto\nmake\nmake install\n````\n\nThen add `extension=mosquitto.so` to your `php.ini`.\n\nThe `--with-mosquitto` argument is optional, and only required if your\nlibmosquitto install cannot be found.\n\n## General operation\n\nThe underlying library is based on callbacks and asynchronous operation. As such, you have to call the `loop()` method of the `Client` frequently to permit the library to handle the messages in its queues. Also, you should use the callback functions to ensure that you only attempt to publish after the client has connected, etc. For example, here is how you would correctly publish a QoS=2 message:\n\n```php\n\u003c?php\n\nuse Mosquitto\\Client;\n\n$mid = 0;\n$c = new Mosquitto\\Client(\"PHP\");\n$c-\u003eonLog('var_dump');\n$c-\u003eonConnect(function() use ($c, \u0026$mid) {\n    $mid = $c-\u003epublish(\"mgdm/test\", \"Hello\", 2);\n});\n\n$c-\u003eonPublish(function($publishedId) use ($c, $mid) {\n    if ($publishedId == $mid) {\n        $c-\u003edisconnect();\n    }\n});\n\n$c-\u003econnect(\"localhost\");\n$c-\u003eloopForever();\n\necho \"Finished\"\n```\n\n## Documentation\n\nFull documentation is [available on ReadTheDocs](http://mosquitto-php.readthedocs.io/).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgdm%2Fmosquitto-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgdm%2Fmosquitto-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgdm%2Fmosquitto-php/lists"}