Created
May 1, 2010 12:57
-
-
Save ryanza/386309 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
global $memcache_obj; | |
global $memcache_key; | |
global $html; | |
$server = 'localhost'; | |
$port = '11211'; | |
$protocol = ($_SERVER['HTTPS'] == 'on') ? 'https' : 'http'; | |
$memcache_key = md5($protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'|'.serialize($_POST).'|'.serialize($_SESSION)); | |
$memcache_obj = memcache_connect($server, (int)$port); | |
$html = memcache_get($memcache_obj, $memcache_key); | |
if ($html) | |
{ | |
echo $html; | |
exit; | |
} | |
ob_start(); | |
?> | |
<?php | |
global $memcache_obj; | |
global $memcache_key; | |
global $html; | |
// get the generate HTML, store it in memcache, and output it to the user | |
$html = ob_get_contents(); | |
memcache_add($memcache_obj, $memcache_key, $html, false, 600); | |
ob_end_flush(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment