A simple cache example (but a little too simple!) )

Source: Internet
Author: User
Cache| Sample//create "cache" directory first to write files

function Bz_cache ($url, $cacheName)
{
Global $cache;
Global $QUERY _string;
Here you can name your own custom.
$filename = "cache/". $cacheName. "," $QUERY _string. ". HTML ";

Here you should also test the file time to see if it expires
(but it's not done here.) Oh! Do It yourself! )
if (file_exists ($filename))
{
ReadFile ($filename);
return 1; Ok i ' v 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; I ' V to execute the file
}
}
}
Put the following line of code at the very beginning of your PHP file
if (Bz_cache ("COMPLETE URL without PARAMS", "An_identifier")) exit ();
Remember, this URL is to be complete, that is, there is a http://in front. But not after the argument.

There is an example on the Web: http://azerclic.labynet.org/doc.php3
The first line is
if (Bz_cache ("Http://azerclic.labynet.org/doc.php3", "Doc")) exit ();
You'll see cached files in http://azerclic.labynet.org/cache/
That ' s all
Good luck!
I estimate that under the WIN32 no problem, under Linux also need to consider permission issues, because generally do not write permission.


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.