/**
  * See if the file is cached on S3.
  * @return mixed
  */
 public function checkForS3Cache()
 {
     /* if using a CNAME alias, set here (ensure is postfixed with /) */
     $s3hostAliasLen = strlen($this->config['s3hostAlias']);
     if (!empty($this->config['s3hostAlias'])) {
         $this->config['s3hostAlias'] = str_replace(array('http://', 'https://'), '', $this->config['s3hostAlias']);
         if (substr($this->config['s3hostAlias'], $s3hostAliasLen - 1, $s3hostAliasLen) != '/') {
             $this->config['s3hostAlias'] .= '/';
         }
     }
     $s3host = !empty($this->config['s3hostAlias']) ? $this->config['s3hostAlias'] : $this->config['s3hostDefault'];
     /* calc relative path of image in s3 bucket */
     $path = str_replace('//', '/', $this->config['s3path'] . $this->cacheFilename);
     $this->expired = true;
     $lastModified = 0;
     $s3imageUrl = '';
     /* check with php's get_headers (slower) */
     if ($this->config['s3headersCheck']) {
         $this->modx->log(modX::LOG_LEVEL_DEBUG, '[phpthumbof] Using get_headers to check modified.');
         $s3imageUrl = 'http://' . str_replace('//', '/', $s3host . urlencode($path));
         $headers = get_headers($s3imageUrl, 1);
         if (!empty($headers) && !empty($headers[0]) && $headers[0] == 'HTTP/1.1 200 OK') {
             if (empty($headers['Last-Modified'])) {
                 $this->expired = true;
             } else {
                 $this->expired = false;
                 $lastModified = $headers['Last-Modified'];
                 $lastModified = strtotime(trim($lastModified[1]));
             }
         } else {
             $this->expired = true;
         }
     } else {
         /* otherwise use amazon's (faster) get object info */
         $this->modx->log(modX::LOG_LEVEL_DEBUG, '[phpthumbof] Using get_object_url to check modified.');
         $s3response = $this->aws->getFileUrl($path);
         if (!empty($s3response) && is_object($s3response) && !empty($s3response->body) && !empty($s3response->status) && $s3response->status == 200) {
             /* check expiry for image */
             $this->expired = false;
             $lastModified = strtotime($s3response->header['last-modified']);
             $s3imageUrl = $s3response->header['_info']['url'];
             if (!empty($this->config['s3hostAlias'])) {
                 $s3imageUrl = str_replace($this->config['s3hostDefault'], $this->config['s3hostAlias'], $s3imageUrl);
             }
         }
     }
     /* check to see if expired */
     if (!empty($lastModified)) {
         /* use last-modified to determine age */
         $maxAge = (int) $this->modx->getOption('phpthumbof.s3_cache_time', null, 24) * 60 * 60;
         $now = time();
         if ($now - $lastModified > $maxAge) {
             $this->expired = true;
         }
     }
     /* if not expired past the cache time, use that url. otherwise, delete from S3 */
     if (!$this->expired) {
         $this->phpThumbOf->endDebug();
         return $s3imageUrl;
     }
     $this->aws->deleteObject($path);
     return true;
 }