function parse() { $export_path = "/home/artica/squid/dbExport"; $TimeFile = "/etc/artica-postfix/pids/exec.squid.stats.protos.php.time"; $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.protos.php.pid"; $unix = new unix(); $pid = @file_get_contents($pidfile); if ($pid < 100) { $pid = null; } if ($unix->process_exists($pid, basename(__FILE__))) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "{$pid} already executed since {$timepid}Mn\n"; } if ($timepid < 240) { return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } @file_put_contents($pidfile, getmypid()); if (!$GLOBALS["VERBOSE"]) { $time = $unix->file_time_min($TimeFile); if ($time < 240) { echo "Current {$time}Mn, require at least 240mn\n"; return; } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); $files = $unix->DirFiles("/var/log/squid", "[0-9]+_proto\\.db"); $currentDay = date("Ymd"); @mkdir($export_path, 0755, true); $q = new mysql_squid_builder(); while (list($filename, $none) = each($files)) { if (!preg_match("#^([0-9]+)_#", $filename, $re)) { continue; } $DayName = $re[1]; $fullpath = "/var/log/squid/{$filename}"; echo " {$fullpath} -> {$DayName} -> {$currentDay}\n"; $berekley = new parse_berekley_dbs(); $tablename = "{$DayName}_proto"; $sql = $berekley->PROTO_DAY_PARSE_TABLE_STRING($tablename); $q->QUERY_SQL($sql); if (!$q->ok) { squid_admin_mysql(0, "MySQL Error", $q->mysql_error, __FILE__, __LINE__); return; } if ($DayName == $currentDay) { $q->QUERY_SQL("TRUNCATE TABLE {$tablename}"); } $array = $berekley->PROTO_DAY_PARSE_DB($fullpath); if (!$array) { continue; } $prefix = $berekley->PROTO_DAY_TABLE_PREFIX($tablename); $sql = $prefix . " " . @implode(",", $array); $q->QUERY_SQL($sql); if (!$q->ok) { squid_admin_mysql(0, "MySQL Error", $q->mysql_error, __FILE__, __LINE__); return; } if ($DayName == $currentDay) { continue; } if (!@copy($fullpath, "{$export_path}/{$filename}")) { continue; } @unlink($fullpath); } }