function checkCacheForFileMatchingFeed ($nameWeShouldLookFor, $cache_path = './cache') {
$cachedFile = false;
$directoryHandle = opendir($cache_path);
//if the dir does not exist
if ($directoryHandle == false) {
//try to make a cache directory
$dirmade = mkdir( $cache_path, 0744);
if($dirmade == false){
//if we can not make the directory exit
echo 'cache does not exist, and unable create a cache directory';
exit();
}
$directoryHandle = opendir($cache_path);
// we just made the directory, there can be no cached file so just stop now
// and go to the next step
return $cachedFile;
} else {
// if the dir does exist let's see what is there
$filesInDirArray = scandir($cache_path);
foreach($filesInDirArray as $fileName) {
//echo '$file';
//if the file is not the directory itself of the parent directory
if ($fileName != "." && $fileName != "..") {
echo $nameWeShouldLookFor . '<br />';
$pattern = '/' . $nameWeShouldLookFor . '/i';
echo $pattern;
$fileNameMatches = preg_match($fileName, $pattern);
if ($fileNameMatches == true) {
echo 'we found a match!';
}
$nameOfFileFoundInCacheDir = $fileName;
}
}
}
// open dir, get list and regex to find file that matches
// if we dont find a cached file we return false
return $cachedFile;
}
function getFileFromSource () {
// use curl to fetch the resource as specified uri
$fileReference = false;
return $fileReference;
}
function writeFetchedResourceToFile () {
// write
}
function serveCachedFileToClient() {
// after we have checked the cache and found a file or
// fetched the we will have a file on disk to serve to the client.
}
function getCachedFileOrLoadResourceThenServeFileFromCache () {
$time = time();
$cache_path = './cache';
$maxCacheAge = 7200;
$remoteFile = 'http://feeds.feedburner.com/MitelFreedomBlog?format=xml';
$nameWeWouldSaveItBy = urlencode($remoteFile);
//echo $nameWeWouldSaveItBy;
$foundCachedfile = checkCacheForFileMatchingFeed ($nameWeWouldSaveItBy);
}