我从 cloudmqtt 获取数据时遇到了问题。我已经从这个链接GitHub下载了项目。
订阅.php
在我的文件中,从文件中调用subscribe.php
了一个函数名procphpMQTT.php
。这是subscribe.php
文件代码
$topics['sensor_data'] = array("qos" => 0, "function" => "procmsg");
$mqtt->subscribe($topics, 0);
while($mqtt->proc()){
}
$mqtt->close();
phpMQTT.php
在我的phpMQTT.php
文件中,定义如下的函数proc 。
function proc( $loop = true){
if(1){
$sockets = array($this->socket);
$w = $e = NULL;
$cmd = 0;
//$byte = fgetc($this->socket);
if(feof($this->socket)){
if($this->debug) echo "eof receive going to reconnect for good measure\n";
fclose($this->socket);
$this->connect_auto(false);
if(count($this->topics))
$this->subscribe($this->topics);
}
$byte = $this->read(1, true);
if(!strlen($byte)){
if($loop){
usleep(100000); //Fatal error shows this line
}
}else{
$cmd = (int)(ord($byte)/16);
if($this->debug) echo "Recevid: $cmd\n";
$multiplier = 1;
$value = 0;
do{
$digit = ord($this->read(1));
$value += ($digit & 127) * $multiplier;
$multiplier *= 128;
}while (($digit & 128) != 0);
if($this->debug) echo "Fetching: $value\n";
if($value)
$string = $this->read($value);
if($cmd){
switch($cmd){
case 3:
$this->message($string);
break;
}
$this->timesinceping = time();
}
}
if($this->timesinceping < (time() - $this->keepalive )){
if($this->debug) echo "not found something so ping\n";
$this->ping();
}
if($this->timesinceping<(time()-($this->keepalive*2))){
if($this->debug) echo "not seen a package in a while, disconnecting\n";
fclose($this->socket);
$this->connect_auto(false);
if(count($this->topics))
$this->subscribe($this->topics);
}
}
return 1;
}
如果我set_limit_time(0);
在 phpMQTT.php 文件顶部使用。然后,当我subscribe.php
在浏览器中浏览时,它永远不会结束加载。
如果我set_limit_time(60);
在 phpMQTT.php 文件顶部使用。然后,当我subscribe.php
在 60 秒后浏览浏览器时,我得到一些数据(6 个数据)并出现此错误。
致命错误:第 275 行的 C:\xampp\htdocs\phpMQTT\examples\phpMQTT.php 中的最大执行时间超过了 60 秒
第 275 行表明usleep(100000);
.
如果我set_limit_time(30);
在 phpMQTT.php 文件顶部使用。然后,当我subscribe.php
在 30 秒后浏览浏览器时,我得到一些数据(3 个数据)并出现此错误。
致命错误:第 275 行的 C:\xampp\htdocs\phpMQTT\examples\phpMQTT.php 中的最大执行时间超过 30 秒
我哪里错了?我该如何解决这个问题?