缓存mysql结果后我的网页加载页面较低,我在firebug上测试并获得缓存结果前后的任何结果,当我不使用缓存时,我的页面可以快速加载,
PHP:
<?php
@session_start();
$filename = '../cache/cache.dump';
$AND = $WHERE = NULL;
if ( isset( $_SESSION['portal_ID'] )) {
$AND = " AND contents.portal = {$_SESSION['portal_ID']}";
$WHERE = " WHERE portal = {$_SESSION['portal_ID']}";
}
// ------------------ CACHE MYSQL RESULTS ----------------
if (filemtime($filename) < time()-24*3600) {
$getTopics=$db->loadAssoc($db->setQuery("SELECT * , categories.title AS category_title,
status_topics.title as status_topic
FROM contents
JOIN categories ON categories.id = contents.category
JOIN status_topics ON status_topics.id = contents.status
$AND"));
$getCategories = $db->loadAssoc($db->setQuery("SELECT * FROM categories $WHERE"));
$getAllCategories = $db->loadAssoc($db->setQuery("SELECT * FROM categories $WHERE"));
$getTags = $db->loadAssoc($db->setQuery("SELECT * FROM tags $WHERE"));
$getAllTags = $db->loadAssoc($db->setQuery("SELECT * FROM tags "));
$getStatusTopics = $db->loadAssoc($db->setQuery("SELECT * FROM status_topics"));
$getPages = $db->loadAssoc($db->setQuery("SELECT * FROM pages $WHERE"));
$getSiteInformation = $db->loadRow ($db->setQuery("SELECT * FROM settings $WHERE"));
$getSubDomainInformation = $db->loadAssoc($db->setQuery("SELECT * FROM sub_domains"));
$getUserInformation = $db->loadAssoc($db->setQuery("SELECT * FROM users $WHERE"));
$getActiveSubDomains = $db->loadAssoc($db->setQuery("SELECT * FROM sub_domains WHERE subdomain_active = 1"));
$getDeactiveSubDomains = $db->loadAssoc($db->setQuery("SELECT * FROM sub_domains WHERE subdomain_active = 0"));
$getUser_information=$db->loadRow($db->setQuery("SELECT * FROM users JOIN permissions on permissions.id = users.permission WHERE username = '{$_SESSION['username']}'"));
file_put_contents($filename, serialize(
array(
$getTopics,
$getCategories,
$getAllCategories,
$getTags,
$getAllTags,
$getStatusTopics,
$getPages,
$getSiteInformation,
$getSubDomainInformation,
$getUserInformation,
$getActiveSubDomains,
$getDeactiveSubDomains,
$getUser_information
)));
}
// ------------------READ FROM CACHE MYSQL RESULTS ----------------
else
{
$data = unserialize(file_get_contents($filename));
list(
$getTopics,
$getCategories,
$getAllCategories,
$getTags,
$getAllTags,
$getStatusTopics,
$getPages,
$getSiteInformation,
$getSubDomainInformation,
$getUserInformation,
$getActiveSubDomains,
$getDeactiveSubDomains,
$getUser_information
) = $data;
}
//print_r($WHERE);
?>
萤火虫导致截图:
缓存后缓存 前
cache.dump 文件大小为 7kb