MySQL vs. checking for file
Posted by: BGilkison
Posted on: 2004-01-10 09:09:00
I'm trying to do some optimization of my site; one particular section, I have images for some (but not all) of the people in my family tree. Currently I have this bit of code:
Function do_g2h_include( $ext ){
if( $ext != '' ){
$dir = $_SERVER['DOCUMENT_ROOT'].'/g2h/';
$file = preg_replace('/i0+/','',basename($_SERVER['SCRIPT_NAME'],".php"));
$file = $dir.('i'.$file.'.'.$ext);
if( file_exists(realpath($file)) ){
if($ext=='inn') echo '<hr />'."n";
include( $file );
}
}
}
This determines the file name, looks to see if a file exists with the same name and requested extension, and if it does, includes that file, which contains a snippet of HTML with the <img> tag(s) to display the picture for that person -- no include file means no picture gets displayed.
I'm wondering though whether accessing the HTML snippet and/or image might be faster to store it in MySQL, and do a lookup to pull back the code? I only do one call to do_g2h_include() per page, but each time it loads a page in my family tree section, it obviously has to check and see if the file exists, and then include it...
Any thoughts?