MySQL vs. checking for file

software development


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:

[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 ‘

include( $file );
[/code]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 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?


Well if you are already connecting to a database it wouldn’t hurt. And then if you do use a table, you can set columns up for filename, width, height, class, style, etc instead of storing the exact HTML you want to use, making it a little more flexible. And also you would have a lot less files to worry about.

:cool: Perl / MySQL / HTML+CSS