Skip to content

Instantly share code, notes, and snippets.

@tsing
Created January 22, 2009 05:56
Show Gist options
  • Save tsing/50436 to your computer and use it in GitHub Desktop.
Save tsing/50436 to your computer and use it in GitHub Desktop.
<?php
$apc_key = 'geowhycommentsrss';
$life = 600;
$api = 'http://pipes.yahoo.com/tsing/geowhycomments?_render=rss';
$timeout = 2;
header("Cache-Control: max-age=$life");
if (! function_exists('apc_fetch')) {
function apc_fetch($key) {
return false;
}
function apc_store($key, $var, $ttl = 0) {
return false;
}
}
$content = apc_fetch($apc_key);
if ($content === false) {
$ch = curl_init($api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
$content = curl_exec($ch);
curl_close($ch);
if ($content !== false) {
$content = str_replace("http://pipes.yahoo.com/pipes/pipe.info?_id=67f8bbcd7af7bf95c6e80ed5245d9845", "http://geowhy.org/feed/comments", $content);
apc_store($apc_key, gzcompress($content, 9), $life);
}
} else {
$content = gzuncompress($content);
header("Via: GWCache");
}
echo $content;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment