function parse() { $export_path = "/home/artica/squid/dbExport"; $TimeFile = "/etc/artica-postfix/pids/exec.squid.stats.notcached-week.php.time"; $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.notcached-week.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 < 30) { 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 < 30) { echo "Current {$time}Mn, require at least 30mn\n"; return; } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); $files = $unix->DirFiles("/var/log/squid", "[0-9]+_NOTCACHED_WEEK\\.db"); $currentWeek = date("YW"); @mkdir($export_path, 0755, true); $q = new mysql_squid_builder(); while (list($filename, $none) = each($files)) { if (!preg_match("#^([0-9]+)_#", $filename, $re)) { continue; } $WeekName = $re[1]; $fullpath = "/var/log/squid/{$filename}"; echo " {$fullpath} -> {$WeekName} -> {$currentWeek}\n"; $berekley = new parse_berekley_dbs(); $tablename = "{$WeekName}_not_cached"; $sql = $berekley->NOT_CACHED_WEEK_PARSE_TABLE_STRING($tablename); $q->QUERY_SQL($sql); if (!$q->ok) { squid_admin_mysql(0, "MySQL Error", $q->mysql_error, __FILE__, __LINE__); return; } if ($WeekName == $currentWeek) { $q->QUERY_SQL("TRUNCATE TABLE {$tablename}"); } $array = $berekley->NOT_CACHED_WEEK_PARSE_DB($fullpath); if (!$array) { continue; } $prefix = $berekley->NOT_CACHED_WEEK_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 ($WeekName == $currentWeek) { continue; } if (!@copy($fullpath, "{$export_path}/{$filename}")) { continue; } @unlink($fullpath); } @mkdir("/usr/share/artica-postfix/ressources/logs/stats", 0755, true); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT SUM(size) as size FROM {$currentWeek}_not_cached")); @file_put_contents("/usr/share/artica-postfix/ressources/logs/stats/NOT_CACHED", $ligne["size"]); @chmod("/usr/share/artica-postfix/ressources/logs/stats/NOT_CACHED", 0755); }