Browse Source

add background fork

Jan Behrens 4 years ago
parent
commit
08c43e9243
2 changed files with 37 additions and 0 deletions
  1. 0 0
      aircoils_convert_csv_to_array.php
  2. 37 0
      index.php

+ 0 - 0
aircois_convert_csv_to_array.php → aircoils_convert_csv_to_array.php


+ 37 - 0
index.php

@@ -48,6 +48,43 @@ else { echo '<meta http-equiv="refresh" content="120">'; $slowrefresh= true; }
 
 ?>
 
+<?php
+
+  // poll ADEI values at 60 sec interval
+  $lastRunLog = 'lastrun.log';
+  $lastRun = 0;
+  if (file_exists($lastRunLog)) {
+    $lastRun = file_get_contents($lastRunLog);
+  }
+  if (time() - $lastRun >= 60) {
+    file_put_contents($lastRunLog, time());
+
+    // fork process
+    umask(0);
+    $pid = pcntl_fork();
+
+    if ($pid < 0) {
+      print('fork failed');
+      exit(1);
+    }
+
+    if ($pid == 0) {
+      // child process -- only do data polling
+      $sid = posix_setsid();
+      if ($sid < 0) exit(2);
+
+      include('poll_adei_data.php');
+      include('poll_HV_data.php');
+
+      exit(0);
+    }
+    else {
+      // parent process -- continue building website
+    }
+  }
+
+?>
+
 </head>
 <body style="background-color:white;">