Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mgdm/mosquitto-php
A wrapper for the Eclipse Mosquitto™ MQTT client library for PHP.
https://github.com/mgdm/mosquitto-php
libmosquitto mosquitto mqtt mqtt-client php
Last synced: 5 days ago
JSON representation
A wrapper for the Eclipse Mosquitto™ MQTT client library for PHP.
- Host: GitHub
- URL: https://github.com/mgdm/mosquitto-php
- Owner: mgdm
- License: bsd-3-clause
- Created: 2013-09-23T00:40:11.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-10-03T14:27:01.000Z (about 1 year ago)
- Last Synced: 2024-10-14T12:36:01.249Z (2 months ago)
- Topics: libmosquitto, mosquitto, mqtt, mqtt-client, php
- Language: C
- Homepage:
- Size: 253 KB
- Stars: 531
- Watchers: 62
- Forks: 147
- Open Issues: 51
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mosquitto-PHP
This is an extension to allow using the [Eclipse Mosquitto™ MQTT client library](http://mosquitto.org) with PHP. See the `examples/` directory for usage.
[![Build Status](https://travis-ci.org/mgdm/Mosquitto-PHP.svg?branch=master)](https://travis-ci.org/mgdm/Mosquitto-PHP)
## PHP 7 support
Thanks 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.
## Requirements
* PHP 5.3+
* libmosquitto 1.2.x or later
* Linux or Mac OS X. I do not have a Windows machine handy, though patches or
pull requests are of course very welcome!## Installation
If 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`.
You may obtain this package using [PECL](http://pecl.php.net):
````
pecl install Mosquitto-alpha
````Alternatively, you can use the normal extension build process:
````
phpize
./configure --with-mosquitto=/path/to/libmosquitto
make
make install
````Then add `extension=mosquitto.so` to your `php.ini`.
The `--with-mosquitto` argument is optional, and only required if your
libmosquitto install cannot be found.## General operation
The 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:
```php
onLog('var_dump');
$c->onConnect(function() use ($c, &$mid) {
$mid = $c->publish("mgdm/test", "Hello", 2);
});$c->onPublish(function($publishedId) use ($c, $mid) {
if ($publishedId == $mid) {
$c->disconnect();
}
});$c->connect("localhost");
$c->loopForever();echo "Finished"
```## Documentation
Full documentation is [available on ReadTheDocs](http://mosquitto-php.readthedocs.io/).