function STATS_hourly_cnx_to_daily_cnx($nopid = false) { $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"; } if (!$nopid) { $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 (!$GLOBALS["FORCE"]) { 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 ($GLOBALS["VERBOSE"]) { echo "LIST_POSTFIX_CNX_HOUR_TABLES = " . count($LIST_POSTFIX_CNX_HOUR_TABLES) . "\n"; } if (count($LIST_POSTFIX_CNX_HOUR_TABLES) > 0) { $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}`"); } } $LIST_POSTFIX_CNX_FAILED_HOUR_TABLES = $q->LIST_POSTFIX_CNX_FAILED_HOUR_TABLES(); if ($GLOBALS["VERBOSE"]) { echo "LIST_POSTFIX_CNX_FAILED_HOUR_TABLES = " . count($LIST_POSTFIX_CNX_FAILED_HOUR_TABLES) . "\n"; } if (count($LIST_POSTFIX_CNX_FAILED_HOUR_TABLES) > 0) { $currentHour = date("YmdH") . "_hfcnx"; while (list($tablename, $timeEx) = each($LIST_POSTFIX_CNX_FAILED_HOUR_TABLES)) { if ($tablename == $currentHour) { continue; } $suffix = date("Ymd", strtotime($timeEx)); $HOUR_FIELD = date("H", strtotime($timeEx)); if (!$q->postfix_buildday_failed_connections($suffix)) { continue; } $desttable = "{$suffix}_dfcnx"; if ($GLOBALS["VERBOSE"]) { echo "{$tablename} -> {$desttable}\n"; } if (!_STATS_hourly_cnx_failed_to_daily_cnx($tablename, $desttable, $HOUR_FIELD)) { continue; } $q->QUERY_SQL("DROP TABLE `{$tablename}`"); } } }