1. Go to this page and download the library: Download zoopcommerce/juggernaut library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zoopcommerce / juggernaut example snippets
// you should always store the cache below the web root for security!!
$cacheDirectory = __DIR__ . '../cache';
$cache = new Zoop\Juggernaut\Adapter\FileSystem($cacheDirectory);
$key = 'yourUniqueKey';
$data = $cache->getItem($key, $success);
// check if cache hit/miss
if ($success === false) {
// cache missed so now we have to execute
// some query that takes a long time
for($i=0;$i<1000000;$i++) {
$data = rand(0, 10000);
}
//save it to cache
$cache->setItem($key, $data);
echo $data;
} else {
// cache hit!
echo $data;
}
$mongo = new MongoClient('mongodb://username:password@localhost:27017');
$collection = $mongo->selectCollection('Cache');
$cache = new Zoop\Juggernaut\Adapter\MongoDB($collection);
$key = 'yourUniqueKey';
$data = $cache->getItem($key, $success);
// check if cache hit/miss
if ($success === false) {
// cache missed so now we have to execute
// some query that takes a long time
for($i=0;$i<1000000;$i++) {
$data = rand(0, 10000);
}
//save it to cache
$cache->setItem($key, $data);
echo $data;
} else {
// cache hit!
echo $data;
}
//coming soon
//coming soon
$pageTtl = 600; //10 mins
$cacheDirectory = __DIR__ . '../cache';
$adapter = new Zoop\Juggernaut\Adapter\FileSystem($cacheDirectory);
$pageCache = new Zoop\Juggernaut\Helper\FullPage($adapter, $pageTtl);
$pageCache->start();
$pageTtl = 600; //10 mins
$database='MyMongoDb';
$username='mymongouser';
$password='mymongopass';
$adapter = new Zoop\Juggernaut\Adapter\MongoDB($database, $username, $password);
$pageCache = new Zoop\Juggernaut\Helper\FullPage($adapter, $pageTtl);
$pageCache->start();
$cacheDirectory = __DIR__ . '../cache';
$adapter = new Zoop\Juggernaut\Adapter\FileSystem($cacheDirectory);
$db = new Zoop\Juggernaut\Helper\Database\Mysqli($cache);
$db->connect($host, $username, $passwd, $database);
$q="SELECT COUNT(`pageviews`) as 'pageviews' FROM `analytics` GROUP BY `date`";
$r = $db->query($q, 600); //second arg is ttl
if($r!==false) {
$pageviews = $db->fetchRow($q)['pageviews'];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.