Browse files

update Feedcache.php to not do a header check on the source when the …

…local file is still valid
  • Loading branch information...
1 parent 62a3ec1 commit 8e62fae3446d2b6043d28c3e6bcc20d2a5e695c1 @erunyon committed Jun 19, 2012
Showing with 7 additions and 6 deletions.
  1. +7 −6 FeedCache.php
View
13 FeedCache.php
@@ -2,11 +2,10 @@
/**
* Cache remote feeds to improve speed and reliability
* Author: Erik Runyon
- * Updated: 2012-04-25
+ * Updated: 2012-06-08
*/
class FeedCache {
- define('ROOT', $_SERVER['DOCUMENT_ROOT']);
private $local;
private $remote;
private $valid_for;
@@ -33,7 +32,9 @@ public function get_data() {
* 3. If that fails, use the local even if its expired so we at least have something
*/
private function populate_data() {
- if( ($this->is_local && !$this->is_expired) || $this->cache_feed() || $this->is_local) {
+ if( $this->is_local && !$this->is_expired ) {
+ return file_get_contents($this->local);
+ } else if( $this->cache_feed() || $this->is_local ) {
return file_get_contents($this->local);
}
}
@@ -82,15 +83,15 @@ private function check_expired() {
private function remote_file_exists($url) {
$ret = false;
$ch = curl_init($url);
-
+
curl_setopt($ch, CURLOPT_NOBODY, true); // check the connection; return no content
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); // timeout after 1 second
curl_setopt($ch, CURLOPT_TIMEOUT, 2); // The maximum number of seconds to allow cURL functions to execute.
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; da; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11');
// do request
$result = curl_exec($ch);
-
+
// if request is successful
if ($result === true) {
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
@@ -99,7 +100,7 @@ private function remote_file_exists($url) {
}
}
curl_close($ch);
-
+
return $ret;
}

0 comments on commit 8e62fae

Please sign in to comment.