mirror of
https://git.code.sf.net/p/quake/website
synced 2024-12-03 09:32:27 +00:00
29 lines
572 B
PHP
29 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);
|
||
|
}
|
||
|
?>
|