RobertP Posted September 20, 2011 Share Posted September 20, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247504-database-type/ Share on other sites More sharing options...
ManiacDan Posted September 20, 2011 Share Posted September 20, 2011 If you use MySQL with query caching turned on, you'll store the results of this query in memory and the access time will be very fast. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/247504-database-type/#findComment-1270981 Share on other sites More sharing options...
RobertP Posted September 20, 2011 Author Share Posted September 20, 2011 any suggested engines? any documentation? ..normally i just create my own engines ... but in the end it comes down to flatfile :/ Quote Link to comment https://forums.phpfreaks.com/topic/247504-database-type/#findComment-1271063 Share on other sites More sharing options...
ManiacDan Posted September 20, 2011 Share Posted September 20, 2011 You create your own engines? What do you mean? For a relatively "flat" setup like this you should use MyISAM. You could also serialize this into an array and stick it in memcache or APC so it's constantly in memory. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/247504-database-type/#findComment-1271078 Share on other sites More sharing options...
RobertP Posted September 20, 2011 Author Share Posted September 20, 2011 <?php /* * @package SytCms * @version 1 * @author Robert.Pettet[rn.pettet@hotmail.com] * @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); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/247504-database-type/#findComment-1271093 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.