PHP Classes

File: Cacher.php

Recommend this page to a friend!
  Classes of Steven   Cacher.php v1.0   Cacher.php   Download  
File: Cacher.php
Role: ???
Content type: text/plain
Description: Simple content cache
Class: Cacher.php v1.0
Author: By
Last change:
Date: 22 years ago
Size: 3,264 bytes
 

Contents

Class file image Download
<? //######################################################## //# Cacher.php v1.0 # //# By Khaled Fadhel # //# alfadhil@hotmail.com # //######################################################## //# # //# Salalah-Network CGI Scripts # //# http://www.salalah.cjb.net # //# # //######################################################## //######################################################## //# # //# You can redistribute this script or use it freely # //# as long as this header is not edited in the script. # //# *I would appreciate a link from you to the URL above.# //######################################################## //# Description: # //# This script allows you to cache the output of # //# almost any script,to speed its execution. # //# To do so launch this script instead of # //# launching the script to be cached. # //######################################################## //#History # //#======= # //# Cacher.php v1.0: 17-01-2001 # //# - First release # //######################################################## //######################################################## //#######change the following three variables.############ //######################################################## //##This is the full URL to your script that will return what you want cached. $scriptURL = 'http://www.YourDomain.com/test.php'; //##This is the name of the cache file. You may specify the location by adding the full path. $cachefile="test.cache"; //##And here you can specify how long to keep using the //##cache file. specified in seconds. $period=60; //######################################################## //############Do not Edit the following.################## //######################################################## function cache() { global $cachefile, $scriptURL, $period; clearstatcache(); if (file_exists($cachefile)){ if((time() - filemtime($cachefile))>= $period){update();} elseif ($f= fopen("$cachefile","r")){ $content = fread($f, filesize($cachefile)); fclose($f); echo $content; } }else{update();} } //################################# function update(){ global $cachefile, $scriptURL, $period; if($content = implode("",file("$scriptURL"))){ if($w = fopen("$cachefile","w")){ fwrite($w,$content); fclose($w); cache(); }else{echo "Unable to open the Cachefile for writing";} }else{echo "Unable to run your content grabbing script";} } //##########Main cache(); ?>