/**
  * Check cache and purge outdated files
  * This method looks for files older than the cache_expire set in the
  * mdb_config and removes them
  * @TODO add a limit on how frequently a purge can occur
  */
 public function purge()
 {
     $cacheDir = $this->config->cachedir;
     $this->logger->debug("[Cache] Purging old cache entries");
     if (is_dir($cacheDir)) {
         if (is_writable($cacheDir)) {
             $thisdir = dir($cacheDir);
             $now = time();
             while ($file = $thisdir->read()) {
                 if ($file != "." && $file != "..") {
                     $fname = $cacheDir . $file;
                     if (is_dir($fname)) {
                         continue;
                     }
                     $mod = filemtime($fname);
                     if ($mod && $now - $mod > $this->config->cache_expire) {
                         unlink($fname);
                     }
                 }
             }
         } elseif (!empty($cacheDir)) {
             $this->logger->critical("[Cache] Cache directory [{$cacheDir}] lacks write permission - purge aborted.");
         }
     } elseif (!empty($cacheDir)) {
         $this->logger->critical("[Cache] Cache directory [{$cacheDir}] does not exist - purge aborted.");
     }
 }
Beispiel #2
0
 /**
  * Request the page from IMDb
  * @param $url
  * @return string Page html. Empty string on failure
  */
 protected function requestPage($url)
 {
     $this->logger->info("[Page] Requesting [{$url}]");
     $req = new MDB_Request($url, $this->config);
     if (!$req->sendRequest()) {
         $this->logger->error("[Page] Failed to connect to server when requesting url [{$url}]");
         return '';
     }
     if (200 == $req->getStatus()) {
         return $req->getResponseBody();
     } elseif ($redirectUrl = $req->getRedirect()) {
         $this->logger->debug("[Page] Following redirect from [{$url}] to [{$redirectUrl}]");
         return $this->requestPage($redirectUrl);
     } else {
         $this->logger->error("[Page] Failed to retrieve url [{url}]. Response headers:{headers}", array('url' => $url, 'headers' => $req->getLastResponseHeaders()));
         return '';
     }
 }
Beispiel #3
0
 /**
  * Check cache and purge outdated files
  * This method looks for files older than the cache_expire set in the
  * mdb_config and removes them
  * @TODO add a limit on how frequently a purge can occur
  */
 public function purge()
 {
     $cacheDir = $this->config->cachedir;
     $this->logger->debug("[Cache] Purging old cache entries");
     $thisdir = dir($cacheDir);
     $now = time();
     while ($file = $thisdir->read()) {
         if ($file != "." && $file != "..") {
             $fname = $cacheDir . $file;
             if (is_dir($fname)) {
                 continue;
             }
             $mod = filemtime($fname);
             if ($mod && $now - $mod > $this->config->cache_expire) {
                 unlink($fname);
             }
         }
     }
 }
Beispiel #4
0
 protected function debug_html($html)
 {
     $this->logger->error(htmlentities($html));
 }