I am using CloudMQTT
as a MQTT broker
in my Pub-Sub based application. I am using my publisher
to publish data to the CloudMQTT server
over a topic
, and I plan to subscribe
to the broker on my webpage to recieve the transmitted information.
I am using this procedure to create a Client
(subscriber): https://www.cloudmqtt.com/docs-php.html
Code goes as follows:
// subscribe.php
require("phpMQTT.php");
$host = "hostname";
$port = port;
$username = "username";
$password = "password";
$mqtt = new phpMQTT($host, $port, "ClientID".rand());
if(!$mqtt->connect(true,NULL,$username,$password)){
exit(1);
}
//currently subscribed topics
$topics['topic'] = array("qos"=>0, "function"=>"procmsg");
$mqtt->subscribe($topics,0);
while($mqtt->proc()){
}
$mqtt->close();
function procmsg($topic,$msg){
echo "Msg Recieved: $msg";
}
Here is the phpMQTT.php
file: https://github.com/bluerhinos/phpMQTT/blob/master/phpMQTT.php
However, the issue in this case is that it recieves data only when the webpage is open.. I want to keep the connection alive even if the webpage is not open to always recieve published messages, how can I do it?
EDIT : I might be open to using some other technology on the server to handle this subscription process, if anyone can recommend some alternatives