Home >Backend Development >PHP Tutorial >PHP caching technology examples_PHP tutorial
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
*/