示例#1
0
 /**
  * 主要check流程
  * @param string $key
  */
 public function check($key = NULL)
 {
     self::getkey($key);
     $ready = $this->cache->get($this->key);
     if ($ready == FALSE) {
         $this->cache->set($this->key, array(time()));
         return;
     }
     $ready_ = $ready;
     if (self::checkCountAndTime($ready_)) {
         $this->rest->error(rest_Code::STATUS_ERROR_API_QUENCY_M);
     }
     unset($ready_);
     array_push($ready, time());
     $this->cache->set($this->key, $ready);
 }
示例#2
0
 /**
  * 主要检测过程
  * @param int $time
  */
 public function ckModified($time = self::DEFAULT_MODIFIED_TIME)
 {
     if (!$this->ifConfig) {
         self::config($time);
     }
     $method = $_SERVER['REQUEST_METHOD'];
     switch ($method) {
         case 'GET':
             $uri = $_SERVER['REQUEST_URI'];
             $params = 0;
             break;
         case 'POST':
             $uri = $_SERVER['REQUEST_URI'];
             $params = $_POST;
             break;
     }
     $key = self::setModifiedKey($uri, $params);
     $cache_time = $this->cache->get($key);
     if ($cache_time) {
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
             $modified_time = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
             if ($cache_time <= $modified_time) {
                 self::mkHeader($cache_time);
                 header("HTTP/1.0 304 Not Modified");
                 die;
             }
         }
     } else {
         $now = time();
         $this->cache->set($key, $now, $this->modified_time);
     }
     self::mkHeader($now);
 }