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();
        }
    }
}
예제 #2
0
$dir = dirname(dirname(__FILE__));
class_exists('Setup', false) or (include $dir . '/classes/Setup.class.php');
class_exists('Utilities', false) or (include $dir . '/classes/Utilities.class.php');
class_exists('Twitter', false) or (include $dir . '/classes/Twitter.class.php');
class_exists('_MySQL', false) or (include $dir . '/classes/_MySQL.class.php');
class_exists('_Logging', false) or (include $dir . '/classes/_Logging.class.php');
class_exists('_MeasurePerformance', false) or (include $dir . '/classes/_MeasurePerformance.class.php');
class_exists('PHPMailer', false) or (include $dir . '/classes/class.phpmailer.php');
class_exists('SMTP', false) or (include $dir . '/classes/class.smtp.php');
$options = getopt("i:");
$parentProcessId = isset($options['i']) ? (int) $options['i'] : 0;
if ($parentProcessId == 0) {
    _Logging::appLog("userJob called without all params");
    exit;
}
$m = new _MeasurePerformance();
$mysql = new _MySQL();
$mysql->connect(Setup::$connectionArray);
// get the user data
$user = Utilities::getAccount();
_Logging::appLog("user job started");
// get the accounts blacklists
Utilities::setBlockLists();
if (empty(Utilities::$domainBlacklists) === true && empty(Utilities::$ipBlacklists) === true) {
    _Logging::appLog("no blacklists configured");
    // mark this one as ran
    $mysql->runQuery("update users set beenChecked = 1, lastChecked = '" . date('Y-m-d H:i:s') . "'");
    exit;
}
//anything to monitor?
$monitorCount = Utilities::getHostCount($mysql);