$mysql->runQuery("update monitors set beenChecked = 0"); // wait for results while (true) { if (!Utilities::is_process_running($parentProcessId)) { _Logging::appLog("parent died - userJob exited"); exit; } $rs = $mysql->runQuery("select ipDomain from monitors where beenChecked = 0 limit 1;"); if ($row = mysqli_fetch_array($rs, MYSQL_ASSOC)) { sleep(4); //wait 4 seconds for them to finish } else { break; } } $m->endWork(); $lastRunTime = (int) $m->runTime; // mark this one as ran $mysql->runQuery("update users set beenChecked = 1, lastChecked = '" . date('Y-m-d H:i:s') . "', lastRunTime = {$lastRunTime}"); $hostsChanged = Utilities::getHostChangeCount($mysql); $errorHosts = Utilities::getHostErrorCount($mysql); if ($hostsChanged > 0 && $user['disableEmailNotices'] == 0) { $table = ""; $summary = ""; $summaryText = ""; $noticeMessage = ""; $url = Setup::$settings['base_url']; $table .= "<br><br><div><a href='{$url}/hosts.php?oc=1'>Hosts with status changes</a> | <a href='{$url}/hosts.php?oc=2'>Blocked Hosts</a> | <a href='{$url}/hosts.php'>All hosts</a></div><br><br>"; $summary .= "<div><strong>"; $summary .= "Total: " . number_format($monitorCount) . "<br/>"; $summary .= "Clean: " . number_format($monitorCount - $errorHosts) . "<br/>";
function monitorProcessWatch($parentProcessId) { $m = new _MeasurePerformance(); $mysql = new _MySQL(); $mysql->connect(Setup::$connectionArray); $parallelProcessesMonitors = Setup::$settings['max_monitor_processes']; $monitorProcesses = array(); $processCountMonitors = 0; $ipDomain = false; while (true) { // are we still running? if (!Utilities::is_process_running($parentProcessId)) { _Logging::appLog("Parent Stopped - monitorStartWatch exited"); exit; } $processCountMonitors = count($monitorProcesses); if ($processCountMonitors < $parallelProcessesMonitors) { $ipDomain = Utilities::getNextMonitor($mysql); if ($ipDomain !== false) { // start it $cmd = 'php ' . dirname(__FILE__) . '/monitorJob.php -h ' . escapeshellarg($ipDomain); $pid = Utilities::run_in_background($cmd); $m->work(1); $monitorProcesses[] = $pid; } } // was there any work? if ($ipDomain === false) { sleep(10); //10 seconds } else { usleep(10000); //ideal time 10ms } // delete finished processes for ($x = 0; $x < $processCountMonitors; $x++) { if (isset($monitorProcesses[$x])) { if (!Utilities::is_process_running($monitorProcesses[$x])) { unset($monitorProcesses[$x]); } } } // fix array index $monitorProcesses = array_values($monitorProcesses); $processCountMonitors = count($monitorProcesses); //randomly reset counter every now and then if (mt_rand(1, 2000) == 1) { $m->endWork(); _Logging::appLog("App Avg Hosts/sec: {$m->avgPerformance}\tMonitor Threads: {$processCountMonitors}/{$parallelProcessesMonitors}"); $m = new _MeasurePerformance(); } } }