Home >Backend Development >PHP Tutorial >A simple cache example is too simple_PHP tutorial

A simple cache example is too simple_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:28:55872browse

// First create the "cache" directory, used to write files function BZ_cache ($url,$cacheName) { global $cache; global $QUERY_STRING; // Here you can name it according to your own habits $filename = "cache/".$ cacheName.",".$QUERY_STRING.".html" ; // Here you should also test the time of the file to see if it has expired // (But it is not done here. Haha! Do it yourself!) 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 } } } //Put the following line of code at the beginning of your PHP file // if ( BZ_cache ("COMPLETE URL WITHOUT PARAMS" , "AN_IDENTIFIER" ) ) exit () ; //Remember, this URL must be complete , that is, there must be http:// in front. But there are no parameters after it. // There is an example on the Internet: http://azerclic.labynet.org/doc.php3 // The first line is // if (BZ_cache ("http://azerclic.labynet.org/doc.php3", "doc " ) ) exit () ; // You will see the cached file at http://azerclic.labynet.org/cache/ // Thats all // Good luck! //I guess there will be no problem under WIN32, but permission issues need to be considered under LINUX, because generally there is no write permission.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531724.htmlTechArticle// First create a cache directory to write files function BZ_cache ($url,$cacheName) { global $cache ; global $QUERY_STRING ; // Here you can name it according to your own habits $filename = ca...
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