使用官方代码里的程序,仅仅修改了URL,我用mqttfx,并且配置好后是可以连接mqtt服务端,但是用PHP程序却一直报这个错,请老师帮忙看一下
<?php
require __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
$worker = new Worker();
$worker->onWorkerStart = function(){
$mqtt = new Workerman\Mqtt\Client('mqtt://localhost:1883');
$mqtt->onConnect = function($mqtt) {
$mqtt->subscribe('test');
};
$mqtt->onMessage = function($topic, $content){
var_dump($topic, $content);
};
$mqtt->connect();
};
Worker::runAll();
---------------------------------------------- WORKERMAN -----------------------------------------------
Workerman version:4.2.1 PHP version:8.0.2
----------------------------------------------- WORKERS ------------------------------------------------
worker listen processes status
none none 1 [ok]
PHP Fatal error: Declaration of Workerman\Mqtt\Protocols\Mqtt::input(string $buffer, Workerman\Connection\ConnectionInterface $connection): int must be compatible with Workerman\Protocols\ProtocolInterface::input($recv_buffer, Workerman\Connection\ConnectionInterface $connection) in F:\mqtt\vendor\workerman\mqtt\src\Protocols\Mqtt.php on line 136
Fatal error: Declaration of Workerman\Mqtt\Protocols\Mqtt::input(string $buffer, Workerman\Connection\ConnectionInterface $connection): int must be compatible with Workerman\Protocols\ProtocolInterface::input($recv_buffer, Workerman\Connection\ConnectionInterface $connection) in F:\mqtt\vendor\workerman\mqtt\src\Protocols\Mqtt.php on line 136
Worker process terminated with ERROR: E_COMPILE_ERROR "Declaration of Workerman\Mqtt\Protocols\Mqtt::input(string $buffer, Workerman\Connection\ConnectionInterface $connection): int must be compatible with Workerman\Protocols\ProtocolInterface::input($recv_buffer, Workerman\Connection\ConnectionInterface $connection) in F:\mqtt\vendor\workerman\mqtt\src\Protocols\Mqtt.php on line 136"
这里粘贴报错
workerman/mqtt 2.1
workerman/workerman 4.2.1 An asynchronous event driven PHP framework for easily building fast, scalable network ap...
mqtt:2.1
跟workerman:4.2.1
不兼容的,我看mqtt
的composer.json
提交记录,其中有一条就是加了workerman
的依赖可以是^4.0
,应该就是这个导致的。。。如果你的项目只有个这个mqtt
,可以试着升级workerman
到版本5
或者降级mqtt
。您好,请问下 哪两个版本的workerman和mqtt可以对得上?
另开一个空目录,在空目录里执行
composer require workerman/mqtt
,再将你的代码也放进去运行就可以了