search
Homephp教程php手册一个简单的cache示例不过太简单了一些

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

Jun 13, 2016 am 10:28 AM
cachefunctionucreatedocumentuseofTable of contentsExampleSimplefirst

// 首先创建"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下还要考虑权限问题的,因为一般都没有写权限。

Statement
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 Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use