for ($a = 0 ;$a<500;$a++){
echo "a = ".$a."||||";
$mqtt->publish( "/1805705204f0468788/getGeneral",$a,);
usleep(500000);
}
只能發(fā)送100個到mqtt服務器上,剩余400個雖然循環(huán) 還在執(zhí)行,但是mqtt服務器就收不到了。不知道為什么求大神解答,mqtt服務器問題已經(jīng)排除
sleep會讓進程睡眠,感覺會影響mqtt消息的確認吧。
試下這個
function publish($a) {
? ? $b = $a + 1;
? ? if ($b >= 500) return;
? ??$mqtt->publish( "/1805705204f0468788/getGeneral",$a,, function()use($b){
? ? ? ? ?Timer::add(0.5, 'publish', , false);
? ? });
}
publish(0);