Forum Moderators: coopster
I opted for this approach instead of reading data from DB is:
DB can sometimes be down or tables might crash
DB might lie on another server and connecting, reading tables might take a little time.
Is there a more better way to speed up my app, like using static php array or any other caching include file techniques which would involve minimal code changes.
Thanks
<?
//setup a cache system so not every call is quiried to the DB
$file = 'table.txt';
$expire = 43200; // 12 hours
if (file_exists($file) &&
filemtime($file) > (time() - $expire)) {
$faq = unserialize(file_get_contents($file));
}
else
{
$faq = array of data retreived from the DB
$OUTPUT = serialize($faq);
$fp = fopen($file,"w");
fputs($fp, $OUTPUT);
fclose($fp);
} // end else
?>
Then you just do whatever you want with the $faq variable. What this does is optimize your time. Instead of having to edit the php file every time you edit the value in your array, you edit the Database and then delete the cache file. The cache file is then regenerated every 12 hours (or whatever you set it to).
Some PHP IDEs have decent built in debuggers, they generally aren't free though. I use PhpED which is pretty good.
A quick and dirty way of debugging is to print out the time taken between code blocks / sections. Once you've found a bottleneck block you can time the individual functions and lines to see if there's anything problematic.