您的位置:首页 > 运维架构 > Linux

centos搭建Mosquitto的php扩展

2016-03-01 00:00 881 查看
参考:https://github.com/mgdm/Mosquitto-PHP
参考:http://blog.csdn.net/ixijing/article/details/40788051

环境搭建

yum配置源

cd /etc/yum.repos.d
wget http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-6/home:oojah:mqtt.repo yum makecache


安装mosquitto

yum install mosquitto libmosquitto-devel mosquitto-clients
service mosquitto start


安装mosquitto-php

pecl install Mosquitto-alpha


php配置

extension=mosquitto.so;//加入php.ini

实现发布的Demo

<?php
/**
* Created by PhpStorm.
* User: edc
* Date: 3/1/16
* Time: 4:12 PM
*/

$client = new Mosquitto\Client();
$client->connect('127.0.0.1',1883);

while (true) {
$mid = $client->publish('/hello', "Hello,I'm a message." , 1, 0);
echo "Sent message ID: {$mid}\n";
sleep(2);
}
$client->disconnect();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mqtt php