I have faced a problem when I get data from cloudmqtt. I have downloaded project from this link GitHub.
subscribe.php
In my subscribe.php
file a function name proc called from phpMQTT.php
file. This is subscribe.php
file code
$topics['sensor_data'] = array("qos" => 0, "function" => "procmsg");
$mqtt->subscribe($topics, 0);
while($mqtt->proc()){
}
$mqtt->close();
phpMQTT.php
In my phpMQTT.php
file a function proc defined like below.
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;
}
If I use set_limit_time(0);
in top of the phpMQTT.php file. Then when I brows subscribe.php
in browser it never ends loading.
If I use set_limit_time(60);
in top of the phpMQTT.php file. Then when I brows subscribe.php
in browser after 60 seconds later I get some data(6 data) with this error.
Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\phpMQTT\examples\phpMQTT.php on line 275
Line 275 indicate that usleep(100000);
.
If I use set_limit_time(30);
in top of the phpMQTT.php file. Then when I brows subscribe.php
in browser after 30 seconds later I get some data(3 data) with this error.
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\phpMQTT\examples\phpMQTT.php on line 275
Where I am wrong? And how can I fix this problem?