centos搭建Mosquitto的php擴展

參考:https://github.com/mgdm/Mosquitto-PHP 參考:http://blog.csdn.net/ixijing/article/details/40788051php

環境搭建

  1. yum配置源
cd /etc/yum.repos.d
wget http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-6/home:oojah:mqtt.repo
yum makecache
  1. 安裝mosquitto
yum install mosquitto libmosquitto-devel mosquitto-clients
service mosquitto start
  1. 安裝mosquitto-php
pecl install Mosquitto-alpha
  1. 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();
相關文章
相關標籤/搜索