}
 if (isset($GLOBALS["CHANNEL"])) {
     if (is_numeric($GLOBALS["CHANNEL"])) {
         if ($GLOBALS["CHANNEL"] > 0) {
             $prefix_channel = "{$GLOBALS["CHANNEL"]} ";
         }
     }
 }
 if ($GLOBALS["DEBUG"]) {
     WLOG("{$GLOBALS["DOMAIN"]}: LOOP domain = {$GLOBALS["DOMAIN"]}");
 }
 $DCOUNT++;
 if (!$GLOBALS["XVFERTSZ"]) {
     $error = urlencode("License Error, please remove Artica categories objects in ACL");
     WLOG("{$GLOBALS["DOMAIN"]}: LOOP():: License Error ! [" . __LINE__ . "]");
     categories_logs("ERROR;License error");
     fwrite(STDOUT, "{$prefix_channel}BH message={$error}\n");
     continue;
 }
 try {
     $sitename = $fam->GetFamilySites($GLOBALS["DOMAIN"]);
     $category = $q->GET_CATEGORIES($sitename);
 } catch (Exception $e) {
     $error = $e->getMessage();
     WLOG("{$GLOBALS["DOMAIN"]}: {$DCOUNT}] LOOP::FATAL ERROR {$error}");
 }
 if ($category != null) {
     if ($GLOBALS["DEBUG"]) {
         WLOG("{$GLOBALS["DOMAIN"]}: LOOP domain = {$GLOBALS["DOMAIN"]} category={$category}");
     }
     fwrite(STDOUT, "{$prefix_channel}OK tag={$category}\n");
function categories_match($gpid, $sitname, $MD5KEY)
{
    $sitname = trim($sitname);
    if (preg_match("#^www\\.(.+)#", $sitname, $re)) {
        $sitname = $re[1];
    }
    if (preg_match("#^(.+):[0-9]+]#", $sitname, $re)) {
        $sitname = $re[1];
    }
    if ($GLOBALS["DEBUG"]) {
        WLOG("Analyze: Group: {$gpid} `{$sitname}`");
    }
    $categories_get_memory = categories_get_memory($gpid, $sitname, $MD5KEY);
    if ($categories_get_memory == 0) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("Group: {$gpid} `{$sitname}` -> MEMORY: `{$categories_get_memory}` ");
        }
        categories_logs("{$gpid};MEMORY;UNKNOWN/NONE");
        if ($GLOBALS["DEBUG"]) {
            WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> UNKNOWN");
        }
        return false;
    }
    if ($categories_get_memory == 1) {
        categories_logs("{$gpid};MEMORY;TRUE/-");
        if ($GLOBALS["DEBUG"]) {
            WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> TRUE");
        }
        return true;
    }
    if ($categories_get_memory == 2) {
        categories_logs("{$gpid};MEMORY;FALSE/-");
        if ($GLOBALS["DEBUG"]) {
            WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> FALSE");
        }
        return false;
    }
    $q = new mysql_catz();
    $categoriF = $q->GET_CATEGORIES($sitname);
    $trans = $q->TransArray();
    if ($GLOBALS["DEBUG"]) {
        WLOG("Group: {$gpid} `{$sitname}` -> RESULTS: `{$categoriF}` ");
    }
    if ($categoriF == null) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("Group: {$gpid} `{$sitname}` -> SET TO  `UNKNOWN` ");
        }
        categories_logs("{$gpid};QUERY;UNKNOWN/NONE");
        categories_set_memory($gpid, $sitname, 0, $MD5KEY);
        return false;
    }
    if (strpos($categoriF, ",") > 0) {
        $categoriT = explode(",", $categoriF);
    } else {
        $categoriT[] = $categoriF;
    }
    while (list($a, $b) = each($categoriT)) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("Group: {$gpid} `{$sitname}` -> category IS: [{$b}] [" . __LINE__ . "]");
        }
        $MAIN[$b] = true;
    }
    if (!isset($GLOBALS["CONFIG"][$gpid])) {
        $filename = "/etc/squid3/acls/catz_gpid{$gpid}.acl";
        $GLOBALS["CONFIG"][$gpid] = unserialize(@file_get_contents($filename));
    }
    $categories = $GLOBALS["CONFIG"][$gpid];
    while (list($category_table, $category_rule) = each($categories)) {
        $category_rule = urlencode($category_rule);
        $categoryname = $trans[$category_table];
        if ($categoryname == null) {
            $categoryname = $category_rule;
        }
        if (isset($MAIN[$categoryname])) {
            if ($GLOBALS["DEBUG"]) {
                WLOG("FOUND `{$categoryname}` -> `{$category_rule}` ");
            }
            categories_logs("{$gpid};QUERY;TRUE/{$categoryname}");
            categories_set_memory($gpid, $sitname, 1, $MD5KEY);
            return true;
        }
    }
    categories_logs("{$gpid};QUERY;FALSE/" . @implode(",", $categoriT));
    categories_set_memory($gpid, $sitname, 2, $MD5KEY);
    return false;
}