I have sections on a page that require a fair amount of resources that I would like to cache, here is an example of the page.
[=== Some Static HTML ===]
[=== PHP Script 1 ===]
[=== Some Static HTML ===]
[=== PHP Script 2 ===]
I would like to put “PHP Script 1” into a cache file eg script1.html and include it rather than processing the whole script, and the same for Script 2.
The problem I have is I can cache the whole page easily and it works but I would like to just cache specific parts (as above) because some things like user session data needs to be live.
I have this class that is meant to be able to stop and start the buffer so I can pull out specific parts without breaking the rest of the page however it doesn’t do what I want.
http://pastebin.com/Ua6DDExw
I would like to be able to go like this below, while it would store the section in a file with a simple php inlcude rather hitting the database.
HTML Content
<?php
$cache->start_buffer("cache_name");
// PHP Script
$cache->end_buffer("cache_name");
?>
HTML Content
<?php
$cache->start_buffer("cache_name");
// PHP Script
$cache->end_buffer("cache_name");
?>
I don’t have access to memcache or anything else like that because this will be going on shared hosting.
Any help would be great,
Thanks
look into using
ob_start()andob_flush()It does what you are looking to do. You’ll need to manually write it to a file. There are cache.php classes out in the wild as well.http://php.net/manual/en/function.ob-start.php