Jump to content

Database Type


RobertP

Recommended Posts

hello everyone, i have a small concern about my current design. i am trying to keep my page loads under 0.01. i am using a file to store lots of semi-static data. the data updates when ever i tell it to. it is a simple cms engine. so the page data is what i am trying to explain. it is either this format...

 

pages.php

<?php exit; ?>
#title,content,access,etc..
Home,welcome to my site,-1,etc...
etc...
..

 

or use mysql.

 

please post your opinions, and if you need more information on my current design just ask.

Link to comment
https://forums.phpfreaks.com/topic/247504-database-type/
Share on other sites

<?php
/*
* @package SytCms
* @version 1
* @author Robert.Pettet[[email protected]]
* @license none
*/

if(!defined('_LOADED'))
exit(header('HTTP/1.0 404 Not Found'));

class sytCache {

private $enabled;
private $dataDirectory;
private $file;
private $logEnabled = false;
private $dataHolder = array();

public function sytCache($enabled,$directory){
	global $config;
	$this->logEnabled = $config['sytCacheLogEnabled'];
	if(!is_dir($directory))
		exit('SytCache: Incorrect data directory.');
	$this->enabled = $enabled;
	$this->dataDirectory = $directory;
	$this->file = $this->dataDirectory.'/sytCacheData.php';
	$this->log3("Instance Created.");
	$this->log3("Time: ".date($config['defaultTimeZoneFormat'],microTimer::getTime()));
}

public function load(){
	if(!$this->enabled)
		return;
	if(!file_exists($this->file))
		exit('SytCache: Incorrect data file.');
	$data = explode("\n",fileManager::getFile($this->file));
	for($i=1;$i<count($data);$i++){
		if($data==null)
			continue;
		$dta = explode("\t",$data[$i]);
		if(isset($dta[2])&&($dta[2]+$dta[3])>microTimer::getTime())
			$this->dataHolder[$dta[0]] = array($dta[1],$dta[2],$dta[3]);
	}
	$this->log3("Cache Loading...");
}

public function get($key){
	if(!$this->enabled)
		return;
	$value = null;
	if(isset($this->dataHolder[$key]))
		$value = unserialize($this->dataHolder[$key][0]);
	$this->log3("GET key={$key} - value={$value}");
	return $value;
}

public function put($key,$value,$holdTime){
	if(!$this->enabled)
		return;
	$this->dataHolder[$key] = array(serialize($value),$holdTime,microTimer::getTime());
	$this->log3("PUT key={$key} - value={$value} - holdTime={$holdTime}");
}

public function purge(){
	if(!$this->enabled)
		return;
	$this->dataHolder = array();
	$this->log3("Data Purged");
}

public function save(){
	if(!$this->enabled)
		return;
	$data = "<?php exit; ?>\n";
	foreach($this->dataHolder as $key => $dataArray){
		if($key)
			$data .= "{$key}\t{$dataArray[0]}\t{$dataArray[1]}\t{$dataArray[2]}\n";
	}
	fileManager::saveFile($this->file,$data);
	$this->log3("Cache Saved.\n");
}

private function log3($line){
	if(!$this->logEnabled)
		return;
	$file = "data/logs/sytCache_log.txt";
	$handler = fopen($file,'a');
	fwrite($handler,$line."\n");
	fclose($handler);
}

}
?>

Link to comment
https://forums.phpfreaks.com/topic/247504-database-type/#findComment-1271093
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.