Advertisement
ewwink

php simple cache

Jan 22nd, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. <?php
  2. function bacaHTML($url){
  3. ...........
  4. }
  5.  
  6. function getFromCache($url){
  7.   if (!file_exists("wincache")) {
  8.     mkdir("wincache");
  9.   }
  10.   $cache_file = "wincache/_jadwal.txt";
  11.   // cache for 61 minutes
  12.   $file = "";
  13.   if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 60 * 61 ))) {
  14.     $file = file_get_contents($cache_file);
  15.   }
  16.   else{
  17.     $file = bacaHTML($url);
  18.     file_put_contents($cache_file, $file, LOCK_EX);
  19.   }
  20.   return $file;
  21. }
  22.  
  23. $kodeHTML = getFromCache('http://................');
  24. ............
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement