Blogroll loading has been a touch slow for me lately, either since Blogrolling.com got a little slower or for some other reason. Thus, I put together a quick and dirty caching system which should speed matters up. If you see “(Cached.)” under one of the blogrolls, now you know why.
See the extended entry for the code used; no support or warranty is available. You’ll want to know a little PHP to use it.
<? function blogroll ($id, $name, $cache) {$base = "/home/httpd/html/popone/static/";
$cache = $base . $cache;
$url = "http://rpc.blogrolling.com/display_raw.php?r=" . $id;ob_start();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
$flag = curl_exec($ch);
curl_close($ch);
$data = ob_get_clean();if ($flag) {
echo $data;
$handle = fopen($cache, 'w');
if ($handle) {
fwrite($handle, $data);
fclose($handle);
}
}
elseif (is_readable($cache)) {
readfile($cache);
echo "(Cached.)";
}
else {
echo "<div class='blogrollmain'>" . $name .
" timed out.</div>\n";
}
}
?>
Be First to Comment