Exemplo n.º 1
0
function STATS_hourly_cnx_to_daily_cnx()
{
    $unix = new unix();
    $GLOBALS["DAYSTATS"] = 0;
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "pidTime: {$pidTime}\n";
    }
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        system_admin_events("Already PID {$pid} running since {$timepid}mn", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    $TimeF = $unix->file_time_min($pidTime);
    if ($TimeF < 60) {
        return;
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $q = new mysql_postfix_builder();
    $LIST_POSTFIX_CNX_HOUR_TABLES = $q->LIST_POSTFIX_CNX_HOUR_TABLES();
    if (count($LIST_POSTFIX_CNX_HOUR_TABLES) == 0) {
        return;
    }
    $currentHour = date("YmdH") . "_hcnx";
    while (list($tablename, $timeEx) = each($LIST_POSTFIX_CNX_HOUR_TABLES)) {
        if ($tablename == $currentHour) {
            continue;
        }
        $suffix = date("Ymd", strtotime($timeEx));
        $HOUR_FIELD = date("H", strtotime($timeEx));
        if (!$q->postfix_buildday_connections($suffix)) {
            continue;
        }
        $desttable = "{$suffix}_dcnx";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$tablename} -> {$desttable}\n";
        }
        if (!_STATS_hourly_cnx_to_daily_cnx($tablename, $desttable, $HOUR_FIELD)) {
            continue;
        }
        $q->QUERY_SQL("DROP TABLE `{$tablename}`");
    }
}