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; } |