热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

wincache缓存mysql,如何缓存动态PHP页面

HowtocachePHPpagewhichhasmysqlquery.Anyexamplewillbegreatandhelpful.解决方案IamusingphpFastCac

How to cache PHP page which has mysql query. Any example will be great and helpful.

解决方案

I am using phpFastCache ( for shared hosting, if you don't want to touch php.ini and root to setup memcached). Check out the Example Menu. They have full detail example, and very easy.

First you set with phpFastCache::set and then get with phpFastCache::get - DONE!

Example: Reduce Database Calls

Your website have 10,000 visitors who are online, and your dynamic page have to send 10,000 same queries to database on every page load. With phpFastCache, your page only send 1 query to DB, and use the cache to serve 9,999 other visitors.

// In your config file

include("php_fast_cache.php");

phpFastCache::$storage = "auto";

// you can set it to files, apc, memcache, memcached, pdo, or wincache

// I like auto

// In your Class, Functions, PHP Pages

// try to get from Cache first.

$products = phpFastCache::get("products_page");

if($products == null) {

$products = YOUR DB QUERIES || GET_PRODUCTS_FUNCTION;

// set products in to cache in 600 seconds = 5 minutes

phpFastCache::set("products_page",$products,600);

}

OUTPUT or RETURN your $products

?>



推荐阅读
author-avatar
mobiledu2502928403
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有