Home > Backend Development > PHP Tutorial > PHP caching technology examples_PHP tutorial

PHP caching technology examples_PHP tutorial

WBOY
Release: 2016-07-13 10:57:56
Original
1289 people have browsed it

php caching technology examples The PHP caching technology that this article will talk about is to generate a temporary cache file from the data and save it to the hard disk, and then delete the cache file according to the time set in the cache file and generate a new cache file again.

php tutorial caching technology examples
The PHP caching technology that this article will talk about is to generate a temporary cache file from the data and save it to the hard disk, and then delete the cache file according to the time set in the cache file and generate a new cache file again.
*/

$filename = 'cachefile.php';
$str ='echo "bb";';
if( is_file( $filename ) )
{
$tmp = readcache( $filename ) ;
}
else
{
createcache( $filename,$str );
}

//Write cache file

function createcache($filename,$str)
{
if( $str =='' ){ return false;}
$fp = fopen($filename,"w+") or die('The cache directory is not possible, please set /www.bKjia.c0m/cache to be writable!');
if( ! fwrite($fp,$str) )
{
echo 'Cannot create cache file!';
exit;
}
fclose($fp);
}

//Read cache file

function readcache($filename)
{
$str = file_get_contents($filename);
if( $str == "" )
{
echo "Failed to read cache file!";
exit;
}
return $str;
}

/*
Original articles on this site, please indicate the source when reprinting http://www.bKjia.c0m/phper/php.html
*/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632041.htmlTechArticlephp caching technology example The php caching technology that this article will talk about is to generate a temporary cache file of data and save it to the hard disk. , and then delete the cache file and regenerate it according to the time set for the cache file...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template