Caching HTML output with PHP?

You can get URLs like that using URL rewriting. Eg: for apache, see mod_rewrite httpd.apache.org/docs/2.2/mod/mod_rewrit... You don't actually need to be creating the files. You could create the files, but its more complicated as you need to decide when to update them if the data changes.

But depending on how awesome or lame your host is, you may or may not have access to URL rewriting...I know that with my 1&1 Beginner package, I don't :( – takua108 Dec 10 '08 at 16:59.

Check ob_start() function ob_start(); echo 'some_output'; $content = ob_get_contents(); ob_end_clean(); echo 'Content generated :'. $content.

I use APC for all my PHP caching (on an Apache server).

Manual caching (creating the HTML and saving it to a file) may not be the most efficient way, but if you want to go down that path I recommend the following (ripped from a simple test app I wrote to do this): $cache_filename = 'scrum_list_CACHED_OUTPUT. Html'; $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 '; $output = ''; // etc // Save the output as manual cache $file = fopen ( $cache_filename, 'w' ); fwrite ( $file, implode($output_final,'') ); fclose ( $file ); print implode($output_final,'').

If you're not opposed to frameworks, try using the Zend Frameworks's Zend_Cache. It's pretty flexible, and (unlike some of the framework modules) easy to implement.

Can use Cache_lite from PEAR: Details here mahtonu.wordpress.com/2009/09/25/cache-p....

I would like to create a cache for my php pages on my site. I have a page for categories which grabs all the categories from the DB, so the script should be able to generate an HTML page of the sort: my-categories.html. Then if I choose a category I should get a my-x-category.

Html page and so on and so forth for other categories and sub categories. Even though they are dynamic.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions