frmatias / easyMQTT

A library to make request to mqtt server
https://packagist.org/packages/frmatias/easy-mqtt
1 stars 0 forks source link

Execution extremely slow #2

Open skyynet opened 5 years ago

skyynet commented 5 years ago

It takes 59 seconds to query 4 values from my Mosquito MQTT Broker. Any idea on how to speed this up?

frmatias commented 5 years ago

I had the same problem, but after this is fast, i'm fig out, problem some delay in the socket connection

Josip84 commented 5 years ago

Hi! This version is much faster then phpMQTT, but still slow. Is there something that I need to change? My Publisher is Windows application. Between is Mosquitto broker. I'm testing on local machine both publisher and subscriber.

frmatias commented 5 years ago

I did not have time yet to change the function that connect to the server, for now I'm calling the function by ajax every 5s so after the first connection got fast

Em qui, 20 de jun de 2019 15:56, Josip84 notifications@github.com escreveu:

Hi! This version is much faster then phpMQTT, but still slow. Is there something that I need to change? My Publisher is Windows application. Between is Mosquitto broker. I'm testing on local machine both publisher and subscriber.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/frmatias/easyMQTT/issues/2?email_source=notifications&email_token=AFOTWAGYUSGRGU7ZQQUKZULP3PHGJA5CNFSM4HOXS3D2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYGJW5I#issuecomment-504142709, or mute the thread https://github.com/notifications/unsubscribe-auth/AFOTWAAZPOWNYLVGUNXVU3DP3PHGJANCNFSM4HOXS3DQ .

Josip84 commented 5 years ago

I did not have time yet to change the function that connect to the server, for now I'm calling the function by ajax every 5s so after the first connection got fast Em qui, 20 de jun de 2019 15:56, Josip84 notifications@github.com escreveu: Hi! This version is much faster then phpMQTT, but still slow. Is there something that I need to change? My Publisher is Windows application. Between is Mosquitto broker. I'm testing on local machine both publisher and subscriber. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#2?email_source=notifications&email_token=AFOTWAGYUSGRGU7ZQQUKZULP3PHGJA5CNFSM4HOXS3D2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYGJW5I#issuecomment-504142709>, or mute the thread https://github.com/notifications/unsubscribe-auth/AFOTWAAZPOWNYLVGUNXVU3DP3PHGJANCNFSM4HOXS3DQ .

I'll try on the same way. Do I need something to change here:

`<?php

require("easyMQTT.php");

$server = "127.0.0.1";     // change if necessary
$port = 1883;                     // change if necessary
$username = "";                   // set your username
$password = "";                   // set your password
$client_id = uniqid(); // make sure this is unique for connecting to sever - you could use uniqid()
$topic = 'sensor/temp';               // topic name

$mqtt = new easyMQTT($server, $port, $client_id);

if ($mqtt->connect(true, NULL, $username, $password)) {
    $msg = $mqtt->subscribe($topic);
    echo $msg;
    $mqtt->close();
}else {
    //improve this
    echo "Time out!\n";
}

?>`
frmatias commented 5 years ago

If you are not working with route in php, you should do a infinity loop with the subscribe method or a timed one

Josip84 commented 5 years ago

If you are not working with route in php, you should do a infinity loop with the subscribe method or a timed one

I'm calling this php from ajax each 5 seconds.