bluerhinos / phpMQTT

a simple php class to connect/publish/subscribe to a MQTT broker
Other
773 stars 460 forks source link

stream_socket_client(): unable to connect (Connection refused) #65

Closed dileep-hegde closed 4 years ago

dileep-hegde commented 6 years ago

I m not able to connect to cloudMQTT using this phpMQTT from web host. I m getting error

Warning: stream_socket_client(): unable to connect to tcp://---.cloudmqtt.com:----- (Connection refused) in /home/***/public_html/vendor/bluerhinos/phpmqtt/phpMQTT.php on line 90

require('../vendor/autoload.php');
header("Refresh:0");
use Bluerhinos\phpMQTT;
$server = "***.cloudmqtt.com";     // change if necessary
$port = ***;                     // change if necessary
$username = "***";                   // set your username
$password = "***";                   // set your password
$client_id = "***"; 
$mqtt = new phpMQTT($server, $port, $client_id);

  if(!$mqtt->connect(true, NULL, $username, $password)) {
        exit(1);
    }
    $topics['test'] = array("qos" => 0, "function" => "procmsg");
    $mqtt->subscribe($topics, 0);

    $start_time = time();
    $done = 0;
    while (!$done && !hasTimedout() && $mqtt->proc()) { } 
    $mqtt->close();
    function procmsg($topic, $msg){
        global $done; 
        //echo "Msg Recieved: ".date("r")."\nTopic:{$topic}\n$msg\n";
    }
    function hasTimedout() 
    { 
        global $start_time; 
        return (time() - $start_time > 1);
   }
>

Both publish and subscribe is working through localhost. but when i uploaded to web hosting it's giving that error.

yeziyuan commented 6 years ago

我和你一样报这样的错误,但是不知道怎么解决,有其他人知道怎么解决这个问题吗

akshaybaweja commented 6 years ago

I am getting the same issue with all of the web hosts of MQTT

suraj050kumar commented 6 years ago

I am also getting the same issue with all of the web hosts of MQTT.

Please help.

kazuser commented 6 years ago

+1

Trying to figure it out together with eclipse/mosquitto.

kamilsweb commented 5 years ago

Getting this error Warning: stream_socket_client(): unable to connect to tcp://localhost:1883 (Connection refused).

I'm missing anything? Do I need to configure the mosquitto-php too I'm using PHPMqtt? Do I need to configure the broker too, if yes then please help in this?

bluerhinos commented 4 years ago

I am restarting this project so having a clear out of old issues (If you believe this is still valid please reopen)