1
0

moving some scripts, making unsubsribe, disconnect and ending clean

This commit is contained in:
2022-01-01 07:35:50 +01:00
parent cac1c638b9
commit f2b24bc0fe
2 changed files with 29 additions and 19 deletions

View File

@ -156,6 +156,8 @@ $client = new Mosquitto\Client();
$client->onConnect('connectResponse');
$client->onDisconnect('disconnectResponse');
$client->onSubscribe('subscribeResponse');
$client->onUnsubscribe('unsubscribeResponse');
$client->onMessage('message');
$client->onLog('logger');
$client->onPublish('publishResponse');
@ -250,25 +252,30 @@ function loadHooks($dir, &$hookList)
function endMoha()
{
global $topics, $nSubscribed ,$client;
global $topics, $nSubscribed ,$client, $logFh, $connected;
$x = 0;
foreach($topics as $topic => $object)
/*foreach($topics as $topic => $object)
{
if ($object->status)
{
$mid = $client->unsubscribe($topic);
$mids[$mid] = $topic;
{*/
$mid = $client->unsubscribe("#");
/*$mids[$mid] = $topic;
}
}
}*/
while ($nSubscribed != 0)
while ($connected)
{
//echo $nSubscribed;0x00124b0022ebac5c
if ( $x++ > 60) exit (0);
if ( $x++ > 60)
{
$client->disconnect();
fclose($logFh);
exit (1);
}
$client->loop();
}
$client->disconnect();
fclose($logFh);
exit(0);
}