Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 13th, 2012  |  syntax: PHP  |  size: 2.08 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function checkCacheForFileMatchingFeed ($nameWeShouldLookFor, $cache_path = './cache') {
  2.         $cachedFile = false;
  3.         $directoryHandle = opendir($cache_path);
  4.        
  5.         //if the dir does not exist
  6.         if ($directoryHandle == false) {
  7.                 //try to make a cache directory
  8.                 $dirmade = mkdir( $cache_path, 0744);
  9.                 if($dirmade == false){
  10.                         //if we can not make the directory exit
  11.                         echo 'cache does not exist, and unable create a cache directory';
  12.                         exit();
  13.                 }
  14.                 $directoryHandle = opendir($cache_path);
  15.                 // we just made the directory, there can be no cached file so just stop now
  16.                 // and go to the next step
  17.                 return $cachedFile;
  18.         } else {
  19.                 // if the dir does exist let's see what is there
  20.                 $filesInDirArray = scandir($cache_path);
  21.                
  22.                 foreach($filesInDirArray as $fileName) {
  23.                         //echo '$file';
  24.                         //if the file is not the directory itself of the parent directory
  25.                         if ($fileName != "." && $fileName != "..") {
  26.                                 echo $nameWeShouldLookFor . '<br />';
  27.                                 $pattern =  '/' . $nameWeShouldLookFor . '/i';
  28.                                 echo $pattern;
  29.                                 $fileNameMatches = preg_match($fileName, $pattern);
  30.                                 if ($fileNameMatches == true) {
  31.                                         echo 'we found a match!';
  32.                                 }
  33.                                 $nameOfFileFoundInCacheDir = $fileName;
  34.                         }
  35.                 }
  36.         }
  37.        
  38.         // open dir, get list and regex to find file that matches
  39.         // if we dont find a cached file we return false
  40.         return $cachedFile;
  41. }
  42.  
  43. function getFileFromSource () {
  44.         // use curl to fetch the resource as specified uri
  45.         $fileReference = false;
  46.        
  47.        
  48.         return $fileReference;
  49. }
  50.  
  51. function writeFetchedResourceToFile () {
  52.         // write
  53.  
  54. }
  55.  
  56. function serveCachedFileToClient() {
  57.         // after we have checked the cache and found a file or
  58.         // fetched the we will have a file on disk to serve to the client.
  59.  
  60. }
  61.  
  62. function getCachedFileOrLoadResourceThenServeFileFromCache () {
  63.  
  64.         $time = time();
  65.         $cache_path = './cache';
  66.         $maxCacheAge = 7200;
  67.         $remoteFile = 'http://feeds.feedburner.com/MitelFreedomBlog?format=xml';
  68.        
  69.         $nameWeWouldSaveItBy = urlencode($remoteFile);
  70.         //echo $nameWeWouldSaveItBy;
  71.         $foundCachedfile = checkCacheForFileMatchingFeed ($nameWeWouldSaveItBy);
  72. }