第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > php mosquitto mosquitto 扩展安装php客户端库-Go语言中文社区

php mosquitto mosquitto 扩展安装php客户端库-Go语言中文社区

时间:2024-03-23 12:03:56

相关推荐

php mosquitto mosquitto 扩展安装php客户端库-Go语言中文社区

原文参考连接:

/blog/mqtt-client-library-encyclopedia-mosquitto-php

1.mosquitto源码安装

源码下载位置:/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/0626/mosquitto.so'

install ok: channel:///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找到扩展模块已经添加成功:

下面开始测试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 -11-10 15:36:49 Sent message ID: 4 Got a message ID 2 on topic /hello with payload: Hello from PHP at -11-10 15:36:51 Sent message ID: 5 Got a message ID 3 on topic /hello with payload: Hello from PHP at -11-10 15:36:53 Sent message ID: 6 Got a message ID 4 on topic /hello with payload: Hello from PHP at -11-10 15:36:55 Sent message ID: 7 Got a message ID 5 on topic /hello with payload: Hello from PHP at -11-10 15:36:57 Disconnected cleanly

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。