Skip to content

Instantly share code, notes, and snippets.

@rskull
Created December 10, 2011 17:22
Show Gist options
  • Save rskull/1455659 to your computer and use it in GitHub Desktop.
Save rskull/1455659 to your computer and use it in GitHub Desktop.
RSSを取得して時間指定でキャッシュする。
<?php
//RSSを取得してキャッシュする。
function getxml ($url, $path, $timer) {
$file_load = true;
//チャージしたRSSファイルの鮮度チェック
if (file_exists($path)) {
$mt = filemtime($path);
if ((time() - $mt) < $timer) {
$file_load = false;
}
}
//新しいRSS取得
if ($file_load) {
$tmp = file_get_contents($url);
file_put_contents($path, $tmp);
}
}
/*
getxml(
$url = 'http://example.com/feed/rss.xml',
$path = 'rss/rss.xml',
$timer = 60 * 60 * 5
);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment