Guest User

Untitled

a guest
Apr 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. ob_start();
  2. echo 'some_output';
  3. $content = ob_get_contents();
  4. ob_end_clean();
  5.  
  6. echo 'Content generated :'.$content;
  7.  
  8. $cache_filename = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING'];
  9. $cache_limit_in_mins = 60 * 32; // this forms 32hrs
  10. // check if we have a cached file already
  11. if ( file_exists($cache_filename) )
  12. {
  13. $secs_in_min = 60;
  14. $diff_in_secs = (time() - ($secs_in_min * $cache_limit_in_mins)) - filemtime($cache_filename);
  15. // check if the cached file is older than our limit
  16. if ( $diff_in_secs < 0 )
  17. {
  18. // it isn't, so display it to the user and stop
  19. print file_get_contents($cache_filename);
  20. exit();
  21. }
  22. }
  23.  
  24. // create an array to hold your HTML output, this is where you generate your HTML
  25. $output = array();
  26. $output[] = '<table>';
  27. $output[] = '<tr>';
  28. // etc
  29.  
  30. // Save the output as manual cache
  31. $file = fopen ( $cache_filename, 'w' );
  32. fwrite ( $file, implode($output_final,'') );
  33. fclose ( $file );
  34.  
  35. print implode($output_final,'');
  36.  
  37. <?php
  38. header("HTTP/1.1 200 OK");
  39. //header("Content-Type: application/json");
  40. header("Content-Encoding: gzip");
  41.  
  42. $cache_filename = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING'];
  43. $cache_filename = "./cache/".md5($cache_filename);
  44. $cache_limit_in_mins = 60 * 60; // It's one hour
  45.  
  46.  
  47. if (file_exists($cache_filename))
  48. {
  49. $secs_in_min = 60;
  50. $diff_in_secs = (time() - ($secs_in_min * $cache_limit_in_mins)) - filemtime($cache_filename);
  51. if ( $diff_in_secs < 0 )
  52. {
  53. print file_get_contents($cache_filename);
  54. exit();
  55. }
  56. }
  57. ob_start("ob_gzhandler");
  58. ?>
  59.  
  60. <?php
  61. $content = ob_get_contents();
  62. ob_end_clean();
  63. $file = fopen ( $cache_filename, 'w' );
  64. fwrite ( $file, $content );
  65. fclose ( $file );
  66. echo gzencode($content);
  67. ?>
  68.  
  69. <?php
  70. include "cache_start.php";
  71. echo "Hello Compress Cache World!";
  72. include "cache_end.php";
  73. ?>
Add Comment
Please, Sign In to add comment