That works great! I fixed a problem with fwrite($fd,$buf);. Changed $buf to $mypage. $buf must have been a variable in the script this came from. Thanks!
Steve Yelvington wrote:
Here's a quick function that takes an url, a filename for a cache file, and an agelimit in minutes (maximum cache time for the file). It returns the data as a string.
The Web server must have permission to write to the directory or file. If the file is missing, filectime() should return 0, so the function should still work.
I have not tested it but it's adapted from similar code that does work.
function getpage($url,$cachefile,$agelimit)
{
$agelimit *= 60; // conv minutes to seconds
$age = time() - filectime($cachefile);
if($age > $agelimit)
{
$mypage = implode('',file($url));
$fd = fopen($cachefile,"w");
fwrite($fd,$buf);
fclose($fd);
return $mypage;
}
else return implode('',file($cachefile));
}