使用 PHP 在 Laravel 上的 mqtt

2023-10-12php开发问题
0

本文介绍了使用 PHP 在 Laravel 上的 mqtt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在我的 raspberry 和我的 Ubuntu 上使用 MQTT.我使用终端作为开始订阅者和发布者,它运行良好.但是现在我想创建一个具有此功能的网站(使用 laravel).我用谷歌搜索了它,但我没有发现任何有趣的东西.有可能吗?怎么做?

I'm using the MQTT on my raspberry and on my Ubuntu. I use terminal for start subscriber and publisher and it works so good. But now I want to create a website (using laravel) with this features. I googled it, but I don't find anything interesting. Is it possible to do and how?

推荐答案

与 HTTP 不同,MQTT 通常用于在应用程序进程和 MQTT 服务器之间打开长时间运行的连接.

Unlike with HTTP, MQTT is typically used by opening a long-running connection between an application process and a MQTT server.

虽然完全有可能打开一个连接,发布一条消息,然后再次关闭套接字,但它并不能真正用于订阅消息流.

While it is perfectly possible to open a connection, publish a single message and then close the socket again, it doesn't really work for subscribing to a stream of messages.

PHP 的典型操作模式是启动一个进程,等待 HTTP 连接,处理请求,然后启动一个新进程.这与具有长时间运行进程的典型 MQTT 模式不太匹配.

PHP's typically mode of operation is to start a process, wait for an HTTP connection, handle the request and then start a new process. This doesn't fit well with the typical MQTT mode of having a long-running process.

随着人们使用 PHP 内置 HTTP 服务器,这种情况开始发生变化.我不确定 Laravel 是否提供了一种机制来在处理请求之间保持变量/TCP 连接.

This had started to change with people using the PHP built-in HTTP server. I am not sure if Laravel provides a mechanism to keep variables/TCP connections in place between handling requests.

或者,可以在长时间运行的 CLI PHP 脚本中订阅 MQTT 主题并将其保留在本地(例如数据库、KV 存储、memcache、redis),然后提供来自数据存储的数据.

Alternatively it is possible to subscribe to a MQTT topic in a long-running CLI PHP script and persisting it locally (for example a database, KV store, memcache, redis) and then serving the data from the datastore.

这在很大程度上取决于您要实现的目标.

It depends a lot on what you are trying to achieve.

这篇关于使用 PHP 在 Laravel 上的 mqtt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17