0

Guys I'm trying to subscribe to a topic in a cloudmqtt freebie server. Server: cloudMQTT

library: phpMQTT.php

publishing the topic seems to be working flawlessly, but it gives me the following error whenever i execute the php file

Error:

Fatal error: Maximum execution time of 30 seconds exceeded in F:\xampp\htdocs\bus_track\live\phpMQTT.php on line 321

PHP Code:

<?php
require("phpMQTT.php");
$server   = "***.cloudmqtt.com"; 
$port     = ******;
$username = "*******";
$password = "********";
$mqtt = new bluerhinos\phpMQTT($server, $port, "ClientID".rand());
//$top=$_GET['topic'];
if(!$mqtt->connect(true,NULL,$username,$password)){
  exit(1);
}


$topics["sensor/temp"] = array("qos"=>0, "function"=>"procmsg");
$mqtt->subscribe($topics,0);

while($mqtt->proc()){
}

$mqtt->close();
function procmsg($topic,$msg){
  echo "Msg Recieved: $msg";
}
?>
AruN
  • 171
  • 4
  • 15

1 Answers1

0

The connection is working fine.

You have a infinite loop in your code:

while($mqtt->proc()){
}

So this section will never end, hence the error message when the runtime hits 30 seconds.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Ok i understand that, but is there any way to keep listening for messages.. so that it will automatically update a table in my database.. – AruN Nov 22 '18 at 07:56
  • What i want to do is, I want to track my phone and store it's coordinates realtime to a db and i need to use mqtt to do it.. strict orders from teacher – AruN Nov 22 '18 at 08:00