pascalwacker/php-mqtt-client
Composer 安装命令:
composer require pascalwacker/php-mqtt-client
包简介
MQTT 3.1.1 library for PHP with TLS support
README 文档
README
MQTT 3.1.1 Client with TSL support in PHP
Note that all calls are blocking until a timeout occurs. If you need some fancy async solution, you'll have to find another repo.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist karpy47/php-mqtt-client
or add
"karpy47/php-mqtt-client": "*"
to the require section of your composer.json.
Requirements
Should work with all recent PHP versions.
Code developed and running in production using PHP v5.6.27
Not tested on PHP v7, please report back!
Basic Usage
$client = new MQTTClient('mqtt-server.domain.com', 8162);
$client->setAuthentication('mqtt-server.username','mqtt-server.password');
$client->setEncryption('cacerts.pem');
$success = $client->sendConnect(12345); // set your client ID
if ($success) {
$client->sendSubscribe('topic1');
$client->sendPublish('topic2', 'Message to all subscribers of this topic');
$messages = $client->getPublishMessages(); // now read and acknowledge all messages waiting
foreach ($messages as $message) {
echo $message['topic'] .': '. $message['message'] . PHP_EOL;
}
$client->sendDisconnect();
}
$client->close();
Credits
Thanks to bluerhinos/phpMQTT and McFizh/libMQTT.
License
Released under the MIT License. Please see License File for more information.
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-12