Advertisement
Guest User

Cache Statique / Soutenez La Quadrature du Net !

a guest
Dec 19th, 2014
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. // Pour ceux qui se demandent comment on fait pour cacher rapidement à l'arrache les 5 pages les plus demandées ;)
  2. // Et soutenez La Quadrature du Net \o/ https://soutien.laquadrature.net/
  3.  
  4. // CACHE STATIQUE BS "poor's-man-cache"
  5. // INTRO
  6. $uris=array("/","/why","/faq","/what","/how","/material");
  7. $duration=300;
  8. if (in_array($_SERVER["REQUEST_URI"],$uris)) {
  9.   $cache="CACHE/root.".$_SERVER["HTTP_HOST"].".".str_replace("/","",$_SERVER["REQUEST_URI"]);
  10.   if (file_exists($cache) && @filemtime($cache)> (time()-$duration) ) {
  11.     readfile($cache);
  12.     exit();
  13.   }  else {
  14.     ob_start();
  15.   }
  16. }
  17.  
  18.  
  19.  
  20. // Retrieve instance of the framework
  21. $f3=require('lib/base.php');
  22. // Initialize CMS
  23. $f3->config('app/config.ini');
  24. // Define routes
  25. $f3->config('app/routes.ini');
  26. // Execute application
  27. $f3->run();
  28.  
  29.  
  30.  
  31. // CACHE STATIQUE OUTRO
  32. if (in_array($_SERVER["REQUEST_URI"],$uris)) {
  33.   file_put_contents($cache,ob_get_flush());
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement