I've got a XML file I read using a file_get_contents and turn
into a simpleXML node every time index.php loads. I suspect this is
causing a noticeable lag in my page-execution time. (Or the wireless
where I'm working could just be ungodly slow-- which it is.)
Is reading a file much more resource/processor intensive than,
say, including a .php file? What about the act of creating a
simpleXML object? What about the act of checking the modification
date on a file? Does anyone have any advice, rumors or intimations
abotu the relative 'heaviness' of these tasks?
The simplest thing to do would be to serialize the xml file into
a variable in.php file for inclusion, then then check the .xml file's
modification date- and use the .xml only if it was newer. Otherwise
include the .php file, de-serialize the simplexml object and go,
Do I lose as much from the file datecheck and de-serializing as I
gain by ditching the file_get_contents? What if instead of
serializing, the datatree was created by outright assignment in
the .php? (losing some of the flexibility nuance of the simpleXML
object, sigh.)
Does include_once impose a processing penalty if the file has
already been included? Is it better to include_once() a required file
once at the top of a file with many possible functions, some of which
do not require the classes and methods you'd be including, or to
include_once many times within the file- specific to the sections that
need it? (A switch statement delineating a file's functions, for
example.)
Is there an internal PHP variable that lets you find out which
files /have/ been included?
If file A requires file B, and file B cannot load, file A suffers
a fatal error and cannot continue..
If file A includes file B, and file B cannot load, file A has a
very unhappy nonfatal error and continues.
If file A includes file B, and file B requires file C, if file C
cannot load, does file A continue executing? How far does the fatal
error reach?
This is a lot of work to go to for 1 XML file... but I'm trying
to abstract a lot of global config and form type creation data. (Some
pages might have 4 or 5 such files being loaded in.) Files that don't
change OFTEN- but do change often /enough/ (especially during
development but also after) that it'd be worth my time to
What about database queries? If a site only updates daily, I can
write the result of the frontpage's database queries to a .xml file
(or serialize into a .php file) every hour to reduce the number of
identical db queries index.php performs. That can be a fairly lengthy
tree- will the performance hit I take by reading a .xml file be worse
than the one I had doing DB queries? Serializing simpleXML object and
unserializing? 'Flattening' to an intermittent .php file with $var =
'value'?
I guess... I'm just kinda lost on the sort of overhead these
functions impose, and I'd like to know before I dive in. Anyone got a
clue?
-Derik