Forum Moderators: coopster
www.example.com/widgets/A
To get B,C,D, and E, I have two options. The simple route would be to pull them from my database. However, this database will be accessed a lot if I do this.
The other route would be to upload all the info in a php array and have that array on every page where there would be a choice. include("widgetarray.php")...then just pull the 4 values where A is.
Which do you think would be better? The load on the database or opening a separate page and searching an array?
include("widgetarray.php")
Which means, if I get you, as you modify these options in the database you'll have to update this file, correct? With that logic, code it in HTML. :-)
Kidding aside, if your options are in separate tables from the product, and optimized, I don't see a problem with reading those as often as required.
One way or another you have to get the data into an array in the first place so your question is a bit confusing. The array is only in memory for as long as the request is being processed. You may need to offer some clarification ...
I'd have widget array updated (with mysql) whenever I update the database. So...abou once a week. Mysql once a week instead of a ton everyday.
If the OS caches the products array file then the disk problem is solved (as it is in MySQL provided cache settings are high enough) but you'll still end up using more memory.
It would make more sense to use the database... one query for each page.
If you're using shared memory, for ease you'd probably want to make all records/rows fixed length for ease of access.
//setup a cache system so not every call is queried to the DB
$file = 'totalfaq_cache.txt';
$expire = 86400; // 24 hours
if (file_exists($file) &&
filemtime($file) > (time() - $expire)) {
$data = unserialize(file_get_contents($file));
}
else
{
$sql = "select x,y,z from database";
$data = YoutDBCall($sql);
$OUTPUT = serialize($data);
$fp = fopen($file,"w");
fputs($fp, $OUTPUT);
fclose($fp);
} // end else
now the $data has the array... mostly from the flat file but every 24hrs its refreshed from the DB.