Created
December 18, 2016 13:59
-
-
Save szihaj/2a31423acfd89ce8f864f3020b20a168 to your computer and use it in GitHub Desktop.
This file contains 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 //var_dump(opcache_get_status()); exit(); phpinfo(); exit(); | |
include 'vendor/autoload.php'; | |
use phpFastCache\CacheManager; | |
$dsn = 'mysql:dbname=employees;host=127.0.0.1'; | |
$user = 'root'; | |
$password = '$ecR3t'; | |
$sql = " | |
/*qc=off*/ SELECT emp.first_name, emp.last_name, emp.birth_date, dep.dept_name | |
FROM dept_emp | |
JOIN employees emp ON dept_emp.emp_no = emp.emp_no | |
JOIN departments dep ON dep.dept_no = dept_emp.dept_no | |
WHERE dept_emp.to_date < '9999-01-01'"; | |
try { | |
$dbh = new PDO($dsn, $user, $password); | |
//$sth = $dbh->prepare($sql); | |
//$sth->execute(); | |
} catch (PDOException $e) { | |
echo 'Connection failed: ' . $e->getMessage(); | |
} | |
CacheManager::setDefaultConfig(array( | |
"path" => '/tmp', | |
)); | |
$InstanceCache = CacheManager::getInstance('files'); | |
//if (isset($_GET['cache_clear'])) { | |
// $InstanceCache->clear(); | |
//} | |
$key = "employees"; | |
$CachedString = $InstanceCache->getItem($key); | |
$time_start = microtime(true); | |
if (is_null($CachedString->get())) { | |
$sth = $dbh->prepare($sql); | |
$sth->execute(); | |
$data = $sth->fetchAll(PDO::FETCH_ASSOC); | |
$CachedString->set($data)->expiresAfter(3600); | |
$saveres = $InstanceCache->save($CachedString); | |
var_dump($saveres); | |
echo "FIRST LOAD"; | |
} else { | |
echo "READ FROM CACHE"; | |
$out = $CachedString->get(); | |
} | |
$time_end = microtime(true); | |
//echo strlen(print_r($out,true)); | |
$execution_time = ($time_end - $time_start); | |
echo '<br><br><br><b>'.sprintf('%.12f', $execution_time).' s</b>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment