add more logs
parent
10a7b9591a
commit
1f069904bc
|
@ -5,7 +5,7 @@ use Mosquitto\Message;
|
||||||
define("STARTED", time());
|
define("STARTED", time());
|
||||||
$mqttHost = getenv("MQTT_HOST");
|
$mqttHost = getenv("MQTT_HOST");
|
||||||
if (!$mqttHost) {
|
if (!$mqttHost) {
|
||||||
logit( "Please set MQTT_HOST environment variable");
|
logit("Please set MQTT_HOST environment variable");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ foreach ($usedConfig as $key => $value) {
|
||||||
|
|
||||||
logit("Connecting to $mqttHost:$mqttPort");
|
logit("Connecting to $mqttHost:$mqttPort");
|
||||||
$mqtt->connect($mqttHost, $mqttPort);
|
$mqtt->connect($mqttHost, $mqttPort);
|
||||||
logit( "Connected");
|
logit("Connected");
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$stats = [
|
$stats = [
|
||||||
|
@ -88,25 +88,29 @@ $mqtt->onMessage(function ($message) use (
|
||||||
$news = true;
|
$news = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
logit( "Subscribing to $mqttTopic with QoS $qos ");
|
logit("Subscribing to $mqttTopic with QoS $qos ");
|
||||||
$mqtt->subscribe($mqttTopic, $qos);
|
$mqtt->subscribe($mqttTopic, $qos);
|
||||||
$mqtt->subscribe($mqttTopic . "/restart", $qos);
|
$mqtt->subscribe($mqttTopic . "/restart", $qos);
|
||||||
logit( "Subscribed");
|
logit("Subscribed");
|
||||||
|
|
||||||
$timer = 0;
|
$timer = 0;
|
||||||
|
|
||||||
logit("Started listening for incoming messages\n will wait 60 seconds before starting to export data");
|
logit(
|
||||||
|
"Started listening for incoming messages\n will wait 60 seconds before starting to export data"
|
||||||
|
);
|
||||||
$realStart = time() + 15;
|
$realStart = time() + 15;
|
||||||
logit( "waiting till " .
|
logit(
|
||||||
|
"waiting till " .
|
||||||
date("Y-m-d H:i:s", $realStart) .
|
date("Y-m-d H:i:s", $realStart) .
|
||||||
" that's in " .
|
" that's in " .
|
||||||
($realStart - time()) .
|
($realStart - time()) .
|
||||||
" seconds");
|
" seconds"
|
||||||
|
);
|
||||||
while (time() < $realStart) {
|
while (time() < $realStart) {
|
||||||
$wait = time() + 5;
|
$wait = time() + 5;
|
||||||
$mqtt->loop(5000);
|
$mqtt->loop(5000);
|
||||||
sleep($wait - time());
|
sleep($wait - time());
|
||||||
logit( "Still waiting...");
|
logit("Still waiting...");
|
||||||
}
|
}
|
||||||
logit("Starting to export data");
|
logit("Starting to export data");
|
||||||
|
|
||||||
|
@ -117,9 +121,10 @@ while ($isRunning) {
|
||||||
$mqtt->loop(1000);
|
$mqtt->loop(1000);
|
||||||
|
|
||||||
if ($lastGC + 60 < time()) {
|
if ($lastGC + 60 < time()) {
|
||||||
gc_collect_cycles();
|
logit("doing Garbage collection...");
|
||||||
|
$c = gc_collect_cycles();
|
||||||
|
logit("Garbage collection done, $c cycles collected");
|
||||||
$lastGC = time();
|
$lastGC = time();
|
||||||
logit("doint GC");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($loopEnd > microtime(true)) {
|
if ($loopEnd > microtime(true)) {
|
||||||
|
@ -387,8 +392,8 @@ function endit(): void
|
||||||
error("Exiting");
|
error("Exiting");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logit(): void
|
||||||
function logit():void{
|
{
|
||||||
echo date("[Y-m-d H:i:s]")." ".implode(" ",func_get_args())."\n";
|
echo date("[Y-m-d H:i:s]") . " " . implode(" ", func_get_args()) . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue