Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ob_start();
- echo 'some_output';
- $content = ob_get_contents();
- ob_end_clean();
- echo 'Content generated :'.$content;
- $cache_filename = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING'];
- $cache_limit_in_mins = 60 * 32; // this forms 32hrs
- // check if we have a cached file already
- if ( file_exists($cache_filename) )
- {
- $secs_in_min = 60;
- $diff_in_secs = (time() - ($secs_in_min * $cache_limit_in_mins)) - filemtime($cache_filename);
- // check if the cached file is older than our limit
- if ( $diff_in_secs < 0 )
- {
- // it isn't, so display it to the user and stop
- print file_get_contents($cache_filename);
- exit();
- }
- }
- // create an array to hold your HTML output, this is where you generate your HTML
- $output = array();
- $output[] = '<table>';
- $output[] = '<tr>';
- // etc
- // Save the output as manual cache
- $file = fopen ( $cache_filename, 'w' );
- fwrite ( $file, implode($output_final,'') );
- fclose ( $file );
- print implode($output_final,'');
- <?php
- header("HTTP/1.1 200 OK");
- //header("Content-Type: application/json");
- header("Content-Encoding: gzip");
- $cache_filename = basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING'];
- $cache_filename = "./cache/".md5($cache_filename);
- $cache_limit_in_mins = 60 * 60; // It's one hour
- if (file_exists($cache_filename))
- {
- $secs_in_min = 60;
- $diff_in_secs = (time() - ($secs_in_min * $cache_limit_in_mins)) - filemtime($cache_filename);
- if ( $diff_in_secs < 0 )
- {
- print file_get_contents($cache_filename);
- exit();
- }
- }
- ob_start("ob_gzhandler");
- ?>
- <?php
- $content = ob_get_contents();
- ob_end_clean();
- $file = fopen ( $cache_filename, 'w' );
- fwrite ( $file, $content );
- fclose ( $file );
- echo gzencode($content);
- ?>
- <?php
- include "cache_start.php";
- echo "Hello Compress Cache World!";
- include "cache_end.php";
- ?>
Add Comment
Please, Sign In to add comment