mosquitto 扩展安装php客户端库

原文参考连接:
http://www.hivemq.com/blog/mqtt-client-library-encyclopedia-mosquitto-php
1.mosquitto源码安装
源码下载位置:http://mosquitto.org/files/source/
选择版本mosquitto-1.4.9.tar.gz
将文件复制到linux系统某一位置
2.解压安装包,编辑config.mk文件屏蔽掉:
WITH_TLS、WITH_TLS_PSK
安装过程出现以下错误:
fatal error: ares.h: No such file or directory
解决方法安装:
apt-get install libc-ares-dev
又出现如下错误:
fatal error: uuid/uuid.h: No such file or directory
安装如下库:
apt-get install uuid-dev
最后 make install
安装完成,通过命令mosquitto启动服务;
启动服务命令:
service mosquitto status 查看服务状态
service mosquitto start 启动服务
service mosquitto stop 停止服务
如果出现未知状态说明已经停止
3.运行下面命令进行安装
pecl install Mosquitto-alpha
此处如果输入不正确会报错:
注意提示输入前缀的时候输入libmosquitto回车;
最后提示安装完成,在php.ini里面添加
extension = mosquitto.so
从配置好的php.index中找到php.ini,在里面添加下面语句
添加地方在938行处
extension=mosquitto.so
重启apache2服务

Build process completed successfully
Installing '/usr/lib/php5/20090626/mosquitto.so'
install ok: channel://pecl.php.net/Mosquitto-0.3.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=mosquitto.so" to php.ini
root@iZ252f8y3biZ:~# /etc/init.d/apache2 restart

然后查看phpinfo找到扩展模块已经添加成功:
mosquitto 扩展安装php客户端库_第1张图片
下面开始测试php是否可以使用:
从浏览器输入对应测试文件目录及文件名:
/mosquittophp/pub.php
查看响应结果:
Sent message ID: 2 I got code 0 Subscribed to a topic Sent message ID: 3 Got a message ID 1 on topic /hello with payload: Hello from PHP at 2016-11-10 15:36:49 Sent message ID: 4 Got a message ID 2 on topic /hello with payload: Hello from PHP at 2016-11-10 15:36:51 Sent message ID: 5 Got a message ID 3 on topic /hello with payload: Hello from PHP at 2016-11-10 15:36:53 Sent message ID: 6 Got a message ID 4 on topic /hello with payload: Hello from PHP at 2016-11-10 15:36:55 Sent message ID: 7 Got a message ID 5 on topic /hello with payload: Hello from PHP at 2016-11-10 15:36:57 Disconnected cleanly

你可能感兴趣的:(阿里云服务器)