call this function client->loopForever() , Often appear Invalid function arguments provided
below is the code I wrote:
public function send($msg){
try {
$mid = 0;
$mqttclient = new \Mosquitto\Client;
$gateway_topic = $this->topic;
$mqttclient->onConnect(function() use ($mqttclient, $gateway_topic,&$mid,$msg)
{
$mid = $mqttclient->publish($gateway_topic,$msg,$this->qos,1);
$mqttclient->disconnect();
});
$mqttclient->setCredentials($this->username, $this->password);
$mqttclient->connect($this->server, $this->port, 5);
$mqttclient->loopforever();
} catch (Exception $e) {
writeException($e);
}
echo "success";
}
please help, thank you!