谁能解workerman mqtt插件只能发送100以内条消息出去呀

dmjlovehj

<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Mysql;
 
use \Workerman\Connection\AsyncTcpConnection;
//启动websocket 用于获取web端信息
$worker = new Worker('websocket://192.168.1.128:2345');
$worker->count = 4;
 
global $times;
$times = 0;
 
global $success;
global $files;
 
$success = 0;
$files = 0;
 
//连接mqtt
$worker->onWorkerStart = function(){
    global $data;
$data= 'admin';
$data = 'public';
global $conn;
$conn = new AsyncTcpConnection('websocket://127.0.0.1:8111');
//连接数据库
global $db;
 
    $db = new \Workerman\MySQL\Connection('127.0.0.1', '3306', 'root', 'root', 'savanee');
    global $mqtt;
    $mqtt = new Workerman\Mqtt\Client('mqtt://192.168.1.128:1883',$data);
 
    $mqtt->onConnect = function($mqtt) {
        $mqtt->subscribe('/server/getGeneral');
    };
    // 查询指纹测试
    //mqtt 消息返回
    /**
     * @param $topic
     * @param $content
     */
    $mqtt->onMessage = function($topic, $content){
        global $db;
        $data=$content;
        $decode = new Decode();
        $instruct_arr = $decode->message($topic,$content);
        $C16ToSttring = $decode ->translate($instruct_arr,$db);
        $req = $decode ->seveMessage($C16ToSttring,$db,"");
        echo $req;
        $array=explode(';', $C16ToSttring);
        if ($array == "request_system_time_set" ){
            global $mqtt;
            $sn = $array;
            $theme = '/'.$sn."/getGeneral";
            $setT =  $decode->setTime($array);
            $equips =  $decode ->sendDeCode16($setT,$db);
            $mqtt->publish($theme, $equips);
        }
 
 
    };
 
 
 
    $mqtt->connect();
};
// 收到消息 用户端消息发送到 mqtt
/**
 * @param $connection
 * @param $datas1
 */
$worker->onMessage = function($connection, $datas1)
{
   
    if ($datas == '1a'){
 
         /*1.获取到全部sn*/
         $equip = new newEquip();
         $arSn = $equip->getAllsn();
         $sum = 0;
         if (!empty($arSn)){
             /*2.通过sn 获取到指纹数组*/
             for ($a = 0; $a<count($arSn);$a++){
                 $sn = $arSn;
                 $did = $arSn;
                 $re =  $equip->getequip($sn,$did);
                 $theme = '/'.$sn."/getGeneral";
                 $re = $theme;
                 /*确认指纹个数*/
                 $eq =  $equip->getequipsum($sn,$did);
 
                 if ($sum<count($eq)){
                     $sum = count($eq);
                     $allequip += $sum;
                 }else{
                     $allequip += $sum;
                 }
 
             }
             /*3.判断数组循环发送*/
             /*二级元素个数*/
 
             /*这里的 sum>100  但是 mqtt 服务器 只能收到100条消息*/
             for ($c = 0;$c<$sum;$c++){
                 for ($b = 0;$b<count($re);$b++){
                     if (!empty($re)){
                      echo "|sum = ".$sum."|||||";
                        $mqtt->publish( $re,$re,);
                        // $mqtt->publish( "/1805705204f0468788/getGeneral",$re,);
                         usleep(500000);
                     }
                 }
             }
         }
 
         $mqtt->onMessage = function($topic, $content) use ($allequip, $connection) {
             global $db;//数据库信息
             global $success;
             global $files;
             $decode = new Decode();
             //返回消息进行数据处理
             $instruct_arr = $decode->message($topic,$content);
             $C16ToSttring = $decode ->translate($instruct_arr,$db);
             //seveMassage方法中有不用user_id的方法,如果 没有 填空
             $req = $decode ->seveMessage($C16ToSttring,$db,"");
             echo  $req;
        
             if ($array == "seve_card"){
                 if($array =="success"){
                     $success = $success +1;
                     $db->query("update  sve_user_task set sut_syn = 1 where sut_sn = '".$array."'and  sut_no ='".substr($array,0,4)."'");
                     echo  "|成功:".$success;
                 }else{
                     $files = $files +1;
                     echo "|失败:".$files;
                 }
             }
 
         };
 
        $lod = $success;
        sleep(3);
        if ($allequip == $success){
            $connection->send("指纹发送完成");
        }else{
            if ($lod == $success){
                $connection->send("指纹发送完成");
            }
        }
 
    }
    
 
};
 
 
Worker::runAll();
``` 
2467 0 0
0个回答

年代过于久远,无法发表回答
🔝