I have tried many servers to use, but it's not working. I am always getting the time out. Is there any special requirement to use the server? Or if I missing something on settings? Actually, I have some dynamic form that contains dynamic fields. After posting any of form I want to do a publish action to the mqtt server. It's working on localhost (wamp server) very good. But after uploading it on my Cpanel hosting it's showing me "time out"
$server = $config['mqtt_settings']['mqtt_server'];
$port = $config['mqtt_settings']['mqtt_port'];
$username = $config['mqtt_settings']['mqtt_username'];
$password = $config['mqtt_settings']['mqtt_password'];
$client_id = md5(uniqid(rand(), true));
$topic = $params['topic_name'];
unset($params['topic_name']);
$message = json_encode($params);
$mqtt = new phpMQTT($server, $port, $client_id);
if ($mqtt->connect(true, NULL, $username, $password)) {
$mqtt->publish($topic, $message, 0);
$ret = [
'status' => 'success',
'msg' => "you have successfully published to " . $topic
];
'op_by' => $config['user']->uid
]);
$mqtt->close();
} else {
$ret = [
'status' => 'warning',
'msg' => "Time out"
];
}