<?php /** * * This demo demonstrates use of global conf.php config file in PageCache. * * It's useful to have settings defined in one file, to avoid repeating yourself * */ require_once __DIR__ . '/../vendor/autoload.php'; //PageCache configuration in a file $config_file = __DIR__ . '/conf.php'; //pass config file $cache = new PageCache\PageCache($config_file); //enable log, by default disabled in conf.php $cache->enableLog(); //getfilepath echo 'Cache filepath, getFilePath(): ' . $cache->getFilePath() . '<br/>'; echo '<hr/>'; //get file name echo 'Cache file name, getFile(): ' . $cache->getFile(); echo '<hr>'; //cache present already? echo 'isChached(): '; if ($cache->isCached()) { echo 'cache exists'; } else { echo 'cache does not exist'; } echo '<hr>'; //get cache file contents
<?php /** * * This demo demonstrates use of global conf.php config file in PageCache. * * It's useful to have settings defined in one file, to avoid repeating yourself * */ require_once __DIR__ . '/../vendor/autoload.php'; //PageCache configuration in a file $config_file = __DIR__ . '/conf.php'; //pass config file $cache = new PageCache\PageCache($config_file); $cache->init(); ?> <html> <body> <h1>Example #2</h1> <h3>This is a demo PageCache page that is going to be cached.</h3> <h3 style="color: red">Demo with conf.php configuration file usage.</h3> <h3>This is a dynamic PHP <i>date('H:i:s')</i> call, note that time doesn't change on refresh: <?php echo date('H:i:s'); ?> .</h3> <br><br> <h4>Check examples/cache/ directory to see cached content. Erase this file to regenerate cache, or it will automatically be regenerated in 10 minutes, as per conf.php</h4> </body> </html>
* NOTE: If you want to cache only URLs before user login or other session manipulations, you could put * PageCache call inside if(!isset($_SESSION[..])) { //run PageCache only on pages without certain Session variable } * */ require_once __DIR__ . '/../vendor/autoload.php'; /** * session is started only when "Enable session" button is pressed */ if (isset($_POST['withsessions']) && $_POST['withsessions'] == '1') { session_start(); //sample session data $_SESSION['demo_session'] = array('my val1', 'my val2'); $_SESSION['user'] = 12; $_SESSION['login'] = true; } $cache = new PageCache\PageCache(); //cache path $cache->setPath(__DIR__ . '/cache/'); //Disable line below and you will see only 1 cache file generated, // no differentiation between session and without session calls // //use session support in cache // $cache->enableSession(); //do disable session cache uncomment this line, or comment line above and see //$cache->disableSession(); //enable log //$cache->enableLog(); //$cache->logFilePath(__DIR__.'/log/cache.log'); //start cache; $cache->init();
if (isset($_POST['withsessions'])) { if ($_POST['withsessions'] == '1') { $_SESSION['excl'] = 1; $_SESSION['PageCache'] = 'PHP full page caching'; } elseif ($_POST['withsessions'] == '2') { $_SESSION['excl'] = 555; $_SESSION['PageCache'] = 'PHP full page caching'; } } echo '<fieldset style="background-color: #eee; padding: 10px;">var_dump($_SESSION) call, before init(), so this content is not cached. Notice how with each button click below actual session value changes, but since it is excluded from tracking, same cache for different session values is generated: '; var_dump($_SESSION); echo 'var_dump ends. All below is cached.</fieldset>'; $cache = new PageCache\PageCache(__DIR__ . '/conf.php'); $cache->enableSession(); //exclude $_SESSION['exc'] from cache strategy. //Comment line below, and cached version for each 'excl' session variable will be saved in a different cache file $cache->sessionExclude(array('excl')); //init $cache->init(); ?> <html xmlns="http://www.w3.org/1999/html"> <head> <style type="text/css"> button { margin: 0; padding: 10px; font-weight: bold; }