mirror of
https://git.code.sf.net/p/quake/website
synced 2024-12-02 17:12:20 +00:00
28 lines
572 B
PHP
28 lines
572 B
PHP
<?
|
|
have ("cache");
|
|
|
|
function cachedURL ($url)
|
|
{
|
|
$cacheDir = siteHome . "/cache";
|
|
$cacheTime = 1800;
|
|
$cacheFile = $cacheDir . '/cached_' . md5 ($url);
|
|
|
|
$timeDifference = @(time () - filemtime ($cacheFile));
|
|
|
|
if ($cacheTime < $timeDifference) { // stale, make a new one
|
|
if ($f = @fopen ($url, 'r')) {
|
|
$content = '';
|
|
while (!feof ($f)) {
|
|
$content .= fgets ($f, 4096);
|
|
}
|
|
fclose ($f);
|
|
if ($f = fopen ($cacheFile, 'w')) {
|
|
fwrite ($f, $content, strlen ($content));
|
|
fclose ($f);
|
|
}
|
|
}
|
|
}
|
|
|
|
return file ($cacheFile);
|
|
}
|
|
?>
|