Пример #1
0
 private function makeMark($data)
 {
     if (!$data) {
         return '';
     }
     self::rksort($data);
     $key = md5(serialize($data));
     $that = $this;
     $mark = infra_once($this->prefix . $key, function () use($data, $that, $key) {
         $isoutdate = true;
         $raise = $this->raise;
         //На сколько символов разрешено увеличивать хэш
         $note = $this->note;
         //При увеличении на сколько записывается сообщение в лог
         $len = $this->len - 1;
         while ($isoutdate && $len < $this->len + $raise) {
             $len++;
             $mark = substr($key, 0, $len);
             $otherdata = infra_mem_get($that->prefix . $mark);
             if ($otherdata && is_array($otherdata['data']) && $otherdata['time']) {
                 if ($otherdata['data'] == $data) {
                     $isoutdate = false;
                     //Такая метка уже есть и она правильная
                 } else {
                     //Решается судьба старой метки
                     $isoutdate = time() > $data['time'] + $this->warrantytime;
                 }
             } else {
                 $isoutdate = false;
             }
         }
         if ($len >= $this->len + $note) {
             $that->notice = 'Mark adding to hash ' . ($len - $this->len) . ' symbol(s) for save time warranty ' . print_r($data, true);
             error_log($that->notice);
         }
         if ($isoutdate) {
             //Все метки актуальны... перезаписываем первую
             $that->error = 'Mark rewrite actual hashmark';
             error_log($that->error);
             $mark = substr($key, 0, $this->len);
         }
         infra_mem_set($that->prefix . $mark, array('time' => time(), 'data' => $data));
         return $mark;
     });
     return $mark;
 }
Пример #2
0
function imager_writeinfo($src, $data)
{
    $file = file($src);
    $l = sizeof($file);
    $metka = preg_replace("/[\\s\n]/", '', $file[$l - 2]);
    $json = json_encode($data, JSON_UNESCAPED_UNICODE);
    if ($metka == 'imager') {
        unset($file[$l - 1]);
        unset($file[$l - 2]);
    } else {
        $metka = preg_replace("/[\\s\n]/", '', $file[$l - 1]);
        if ($metka == 'imager') {
            unset($file[$l - 1]);
            unset($file[$l - 2]);
            unset($file[$l - 3]);
            unset($file[$l - 4]);
            unset($file[$l - 5]);
        } else {
            $metka = preg_replace("/[\\s\n]/", '', $file[$l - 4]);
            if ($metka === 'imager') {
                unset($file[$l - 1]);
                unset($file[$l - 2]);
                unset($file[$l - 3]);
                unset($file[$l - 4]);
                unset($file[$l - 5]);
                unset($file[$l - 6]);
                unset($file[$l - 7]);
                unset($file[$l - 8]);
            }
        }
    }
    $l = sizeof($file);
    $file[] = "\n" . 'imager';
    $file[] = "\n" . $json;
    infra_once('imager_readInfo', $data, array($src));
    return file_put_contents($src, implode('', $file));
}