mqtt实例 php_一个新的开源PHP MQTT 客户端代码库——PHPMQTT

PHPMQTT是Andrew Milsted开发的一个新的PHP MQTT客户端库,作为PHP_SAM的替代品。该项目仍处于早期阶段,目前仅支持发布功能,但提供了简单易用的接口,只需一个文件和几个基本函数即可开始使用。这使得PHP开发者可以更轻松地集成MQTT,推动MQTT技术的普及。
摘要由CSDN通过智能技术生成

It seems finally we may be freed from the unstable shakiness which is embodied in PHP_SAM – the only PHP based MQTT client….until now.

Project SAM is a PHP library for several different pubsub messaging systems, one being MQTT. However it suffers from a very restrictive licence, a lack of maintenance and quite a few bugs. Previously there was no choice if you wished to use MQTT and PHP, now Andrew Milsted(@bluerhinos) has started to produce an alternative: phpMQTT

phpMQTT is only in infancy at the moment and currently only publishing is fully functional, with some bugs to be ironed out of subscriptions, however for anyone who has used PHP_SAM it provides a refreshingly easy way to start using MQTT – consisting of just one file and a handful of simple functions. An example of publishing a message (written by Andrew Milsted) is shown below:

require("phpMQTT.php");

$mqtt = new phpMQTT(); /* broker(broker address, broker port, client id); */

$mqtt->broker("example.com", 1883, "PHP MQTT Client");

$mqtt->connect(); /* publish( topic, message, qos); */

$mqtt->publish("bluerhinos/phpMQTT/examples/publishtest","Hello World!",0);

$mqtt->close();

The main point to note from this example is that unlike PHP_SAM I could just download the library and run it straight away, no looking through to see why it was causing errors, no patching to work with mosquitto, it just worked (all the bits that claimed to work anyway). It’s also simple enough that anyone with a basic grasp of any C style language and MQTT could start using straight away with any documentation!

The MQTT scene has see

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值