Home php教程 php手册 PHP写的一个简单的cache示例

PHP写的一个简单的cache示例

Jun 21, 2016 am 08:57 AM

一个简单的cache示例(不过太简单了一些!)

?// 首先创建"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 i'v 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 ;???///??i'v 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/
// That's all??
//好运!
//我估计在WIN32下没问题,在LINUX下还要考虑权限问题的,因为一般都没有写权限



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)