I am using Memcached and i will put all my heavy load pages with this code.
PHP Code:
<?
////////////////////////////////////////////////////////////////
// index.php
//
// This is an example of memcaching a full static page
////////////////////////////////////////////////////////////////
// This is the page you want to cache
$url = "http://www.mysite/mydynamicpage";
// This function grabs the HTML of the page
function ScrapePage () {
global $url;
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, ""); // add POST fields
$result = curl_exec($ch); // run the whole process
curl_close($ch);
return $result;
}
// This function stores the HTML into memcache and update if its older than 3 mins
function MemCacheFunction($function_name)
{
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
$memcache_key = md5('sometextkey'.$function_name);
if ( $memcache_result = $memcache->get($memcache_key) )
{
//echo "It Worked!";
return $memcache_result;
}
//echo "Couldn't Find Key: ".$memcache_key;
$ret = '';
$ret .= $function_name();
$memcache->set($memcache_key, $ret, false, 180);
return $ret;
}
// A simple condition determines whether to load page from Memcache or process the dynamic page
if ($_COOKIE["loggedin"] == "yes") {
include ("index_dynamic.php");
} else {
echo MemCacheFunction("ScrapePage");
}
?>
But my problem is how i will call my dynamic page when a user is logged in.
example:
PHP Code:
if ($_COOKIE["loggedin"] == "yes") {
include ("index_dynamic.php");
Thank you
Bookmarks