// 首先创建"cache"目录 ,用来写文件
function bz_cache ($url,$cachename)
{
global $cache ;
global $query_string ;
// 这里你可以按自己的习惯命名
$filename = "cache/".$cachename.",".$query_string.".html" ;
// 这里你还应该测试一下文件的时间,看是否过期
//(不过这里没做。呵呵!自己完成吧!)
if ( file_exists ( $filename) )
{
readfile ($filename) ;
return 1 ; /// ok iv send the html page
}
else
{
if ( ! isset ($cache ) )
{
$fcontents = join (, file ($url."?".$query_string."&cache=t"));
$fp = fopen ($filename , "w");
fwrite ($fp, $fcontents );
fclose ( $fp) ;
return 0 ; /// iv to execute the file
}
}
}
// 在你的php文件的最开始放入下面一行代码
// if ( bz_cache ("complete url without params" , "an_identifier" ) ) exit () ;
//记住,这个url是要完全的,即前面要有http://。但后面不要参数。
// 网上有一个例子:http://azerclic.labynet.org/doc.php3
// 第一行是
// if ( bz_cache ("http://azerclic.labynet.org/doc.php3" , "doc" ) ) exit () ;
// 你会看到cached文件在 http://azerclic.labynet.org/cache/
// thats all
//好运!
//我估计在win32下没问题,在linux下还要考虑权限问题的,因为一般都没有写权限。