做异步消息转发的时候,使用mqtt,连接一段时候,就会出现报错,这改如何解决?
$asyCon = new AsyncTcpConnection('ws://ws.xxx.com');
$asyCon->onConnect = function(AsyncTcpConnection $asyCon){
$asyCon->send(json_encode(['action' => 'test','params' => 'test']));
};
$asyCon->onMessage = function (AsyncTcpConnection $con, $data){
$mqtt = new Workerman\Mqtt\Client('mqtt://127.0.0.1:1883');
$mqtt->onConnect = function($mqtt) use($data) {
$mqtt->publish('resData', $data);
};
$mqtt->onError = function ($data) use ($con){
echo $data->getMessage().":".$data->getCode().PHP_EOL;
};
$mqtt->connect();
};
Connection timeout 101