Php Cache technical instance _ PHP Tutorial

Source: Internet
Author: User
Php Cache technology instance. Php Cache technology example the php Cache technology mentioned in this article is to generate a temporary cache file for data and save it to the hard disk, then, delete the cache file based on the time set by the cache file to generate another php Cache technology instance. This article describes the php Cache technology that generates a temporary cache file and saves it to the hard disk, then, delete the cached file and generate a new cache file based on the time set for the cached file.

Php Tutorial cache technology example
The php Cache technology mentioned in this article is to generate a temporary cache file for data and save it to the hard disk. then, delete the cache file according to the time set by the cache file to generate a new cache file again.
*/

$ Filename = 'cachefile. php ';
$ Str = 'echo "bb ";';
If (is_file ($ filename ))
{
$ Tmp = readcache ($ filename );
}
Else
{
Createcache ($ filename, $ str );
}

// Write the cached file

Function createcache ($ filename, $ str)
{
If ($ str = '') {return false ;}
$ Fp = fopen ($ filename, "w +") or die ('The cache directory is not possible. set/www. bKjia. c0m/cache to writable! ');
If (! Fwrite ($ fp, $ str ))
{
Echo 'the cache file cannot be created! ';
Exit;
}
Fclose ($ fp );
}

// Read the cached file

Function readcache ($ filename)
{
$ Str = file_get_contents ($ filename );
If ($ str = "")
{
Echo "an error occurred while reading the cached file! ";
Exit;
}
Return $ str;
}

/*
Original site article, reprinted with source http://www.bKjia. c0m/phper/php.html
*/

Http://www.bkjia.com/PHPjc/632041.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632041.htmlTechArticlephp cache technology instance this article will talk about the php Cache technology is to generate a temporary cache file to save the data to the hard disk, and then according to the cache file set time to delete the cache file again...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.