Пример #1
0
 protected function __construct($trackHits = true)
 {
     $this->engine = CacheEngineFactory::getEngine();
     $this->semengine = SemaphoreEngineFactory::getEngine();
     $this->recacheWaiting = array();
     $this->trackHits = $trackHits;
 }
Пример #2
0
 protected function indexName($name, $id)
 {
     $iwords = $this->getIndexable($name);
     if (count($iwords) > 0) {
         $sem = SemaphoreEngineFactory::getEngine();
         $sindex = array();
         $create = array();
         $docreate = false;
         $query = new Query('SELECT');
         $query->field('term');
         $query->field('app_id_array');
         $query->from('search_name_index');
         foreach ($iwords as $iword) {
             $sindex[$iword] = array();
             $create[$iword] = true;
             $docreate = true;
             $query->where('term = ?', $iword, 'OR');
         }
         $stmt = $query->prepare();
         $semkey = Config::getVal('recache', 'unique_name') . ":LOCK:sindex";
         $sem->acquire($semkey);
         $stmt->execute();
         while ($row = $stmt->fetchObj()) {
             $create[$row->term] = false;
             $sindex[$row->term] = unserialize($row->app_id_array);
         }
         unset($query);
         unset($stmt);
         $iquery = new Query('INSERT');
         $iquery->ignore();
         $iquery->intoTable('search_name_index');
         $iquery->intoField('term');
         $iquery->intoField('app_id_array');
         $uqueries = array();
         foreach ($iwords as $iword) {
             if (!in_array($id, $sindex[$iword])) {
                 $sindex[$iword][] = $id;
                 $this->cm->set("search_name_index:{$iword}", $sindex[$iword], 0);
             }
             if ($create[$iword]) {
                 $iquery->VALUES('(?, ?)', array($iword, serialize($sindex[$iword])));
             } else {
                 $query = new Query('UPDATE');
                 $query->table('search_name_index');
                 $query->set('app_id_array = ?', serialize($sindex[$iword]));
                 $query->where('term = ?', $iword);
                 $uqueries[] = $query;
             }
         }
         if ($docreate) {
             $stmt = $iquery->prepare();
             unset($iquery);
             $stmt->execute();
         }
         foreach ($uqueries as $uquery) {
             $stmt = $uquery->prepare();
             $stmt->execute();
         }
         $sem->release($semkey);
     }
 }
Пример #3
0
{
    $expire30min = time() - 30 * 60;
    $expire2hr = time() - 2 * 60 * 60;
    $expire6hr = time() - 6 * 60 * 60;
    $expire12hr = time() - 12 * 60 * 60;
    $expire1day = time() - 24 * 60 * 60;
    $expire2day = time() - 2 * 24 * 60 * 60;
    $expire1week = time() - 7 * 24 * 60 * 60;
    foreach ($list as $ip => $info) {
        if ($info['killed_hits'] < 50 && $info['timestamp'] <= $expire30min || $info['killed_hits'] < 100 && $info['timestamp'] <= $expire2hr || $info['killed_hits'] < 200 && $info['timestamp'] <= $expire6hr || $info['killed_hits'] < 300 && $info['timestamp'] <= $expire12hr || $info['killed_hits'] < 500 && $info['timestamp'] <= $expire1day || $info['killed_hits'] < 1000 && $info['timestamp'] <= $expire2day || $info['timestamp'] <= $expire1week) {
            unset($list[$ip]);
        }
    }
}
// Get resources
$sem = SemaphoreEngineFactory::getEngine();
$cm = RECacheManager::getInstance();
// Should we be bot-blocking?
if (substr($_SERVER['REMOTE_ADDR'], 0, 11) != "193.253.141" && substr($_SERVER['REMOTE_ADDR'], 0, 10) != "142.22.186" && $_SERVER['REMOTE_ADDR'] != "62.201.129.226" && $cm->checkIfFrequent(10, 20, 'BOTTEST:' . $_SERVER['REMOTE_ADDR'])) {
    $sem->acquire(Config::getVal('general', 'site_name') . ":bot_list");
    $list = $cm->get("bot_list");
    if (!is_array($list)) {
        $list = array();
    }
    if (isset($list[$_SERVER['REMOTE_ADDR']])) {
        $list[$_SERVER['REMOTE_ADDR']]['killed_hits']++;
    } else {
        BOTLIST_purgeOldItems($list);
        $list[$_SERVER['REMOTE_ADDR']] = array();
        $list[$_SERVER['REMOTE_ADDR']]['killed_hits'] = 1;
    }