I need a solution for caching PHP info on a dynamic page AND include the meta info. My problem is I am using a caching code that is saving my page info from the code and below, but not the meta info.
look at my page My Dynamic Page
My software is dynamically creating this page from the ID 5351 (the song in my database) I am using php to go grab the song info. To make this process a bit more efficient, I have set up PHP caching. I am caching this now using the below code….
<?php
$cachefile = "cache/".$reqfilename.$cache_folder.md5($_SERVER['REQUEST_URI']);
$cachetime = 11000 * 60; // 110000 minutes
// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && (time() - $cachetime
< filemtime($cachefile)))
{
include($cachefile);
echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))."
-->n";
exit;
}
ob_start(); // start the output buffer
?>
The PHP Cache is being accomplished using this, but my problem is it only caches the PHP info from this code and below. The reason this is a problem, is because i also use PHP in the meta info for my Open Graphic tags. The OG is so people can “like” my music in Facebook. Here is what my OG tags look like.
<title>Chennai Christian Radio</title>
<meta property="og:title" content="<?php echo $song->title; ?> by <?php echo $song->artist; ?> - Found on Chennai Christian Radio"/>
<meta property="og:type" content="song"/>
<meta property="og:url" content="http://chennaichristianradio.com/PHP/web/songinfo.php?songID=<?php echo $song->ID; ?>"/>
<meta property="og:image" content="<?php echo $song->picture; ?>"/>
<meta property="og:site_name" content="Chennai Christian Radio"/>
<meta property="fb:admins" content="1013572426"/>
<meta property="og:description"
content="Chennai Christian Radio is your last stop for today's best Christian Music. http://chennaichristianradio.com"/>
So…… What is the solution for caching my dynamic page AND include the meta info. That is defiantly the best option, but with my current code, it still queries my MYSql server for the Meta info and the song info. I thought by creating static pages for this and telling my software to point to these pages instead of querying my database it would be more efficient, as well as help in reducing my PHP traffic back to my server. Thank you for any help that can be offered.
If you want to achieve that you should cache the the final html page created by your php script or you could also look into varnish cache.
If you want do this using php then what I will do is start output buffering and write the contents of the output buffer to cache just before sending to client. Something like the following(pseudocode)
I hope the above pseudocode helps