PHP Caching Technology (1/4)

Source: Internet
Author: User

Look at this cache class first

<?php

The code is as follows Copy Code

Class cache{
/*
class Name:cache
Description:control to cache data, $cache _out_time are a array to save CAC He date is out.
version:1.0
Author: Old farmer Cjjer
last modify:2006-2-26
author url:http://www.111cn.net*/
Private $cache _dir;
Private $expiretime =180;//cache time is 60 seconds
function __construct ($cache _dirname) {
    if (! @is_ Dir ($cache _dirname)) {
        if (! @mkdir ($cache _dirname,0777)) {
         $this->warn (' Cached files do not exist and cannot be created, need to be created manually. ');
        return false;
       }
   }
$this->cache_dir    =    $cache _dirname;
}
Function __destruct () {
    echo ' Cache class bye. ';
}

function Get_url () {
if (!isset ($_server[' Request_uri ')) {
$url = $_server[' Request_uri '];
}else{
$url = $_server[' Script_name '];
$url. = (!empty ($_server[' query_string '))? '?' . $_server[' query_string ']: ';
}

return $url;
}

function warn ($errorstring) {
echo "<b><font color= ' red ' > Error:<pre>". $errorstring. " </pre></font></b> ";
}

function Cache_page ($pageurl, $pagedata) {
if (! $fso =fopen ($pageurl, ' W ')) {
$this->warns (' Unable to open cache file. '); /trigger_error
return false;
}
if (!flock ($fso, lock_ex)) {//LOCK_NB, exclusive lock
$this->warns (' Unable to lock cache file. '); /trigger_error
return false;
}
if (!fwrite ($fso, $pagedata)) {//write byte stream, serialize write to other format
$this->warns (' Unable to write cache file. '); /trigger_error
return false;
}
Flock ($fso, Lock_un);/release lock
Fclose ($FSO);
return true;
}

home 1 2 3 4 last page

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.