473,714 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading a XML file on every page execution - convert to PHP?

I've got a XML file I read using a file_get_conten ts 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_conten ts? 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
Jun 2 '08 #1
2 2839
Derik wrote:
I've got a XML file I read using a file_get_conten ts 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?
Two different things. Just reading a file does not include any parsing.
Including a php file requires the file be read then parsed. So
including is always going to be slower.
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_conten ts? 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.)
The date check will also be quick. Deserialization takes some time,
also, but probably not as much as parsing the xml code in the first place.

As far as the assignment goes - it just depends on how much you're
doing. But it *probably* will be faster than the xml but slower than
serializing.

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.)
Just the overhead of PHP checking to see if the file has been included
or not. But that has to be done every time include_once() is called,
anyway.
Is there an internal PHP variable that lets you find out which
files /have/ been included?
No.
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?
If file B required file C, and file C cannot load, you get a fatal error.
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'?
Personally, I'd use a database and skip the XML all together. And if
the data are called regularly, they will probably already be in the
database cache.
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
Rule #1: Don't prematurely optimize.
Rule #2: If you have performance problems, find the cause.

In your case it could be the PHP code or the wireless connection. Find
out by putting a call to microtime() at the start and end of your
script. Subtract the two return values and print the amount of time it
takes to execute your code.

If you find it is too long, move the microtime() calls around to isolate
the code that's taking a long time.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jun 2 '08 #2
Jerry Stuckle wrote:
>
Rule #1: Don't prematurely optimize.
Rule #2: If you have performance problems, find the cause.

In your case it could be the PHP code or the wireless connection. Find
out by putting a call to microtime() at the start and end of your
script. Subtract the two return values and print the amount of time it
takes to execute your code.

If you find it is too long, move the microtime() calls around to isolate
the code that's taking a long time.

Profiling with microtime() is good for simple code and one-off
situations, but if you find yourself profiling a lot (which you should)
then installing an engine-level profiler (like xdebug) on your
development server can be extremely helpful. I have uncovered some
truly "WTF?" bottlenecks that I never would have thought to wrap in
microtime() calls.

http://pecl.php.net/package/Xdebug
To address the OP on a couple of points:

1) Last time I checked, SimpleXML objects cannot be serialized easily.
Even if they could, you wouldn't gain much time by using PHP
serialization over XML.

2) Unless your XML document is very large, the amount of time needed to
parse it is fairly negligible in the scope of a web request. Unless you
have a high-traffic site, it probably doesn't need to be a huge concern.
If your XML document IS very large, you should probably be using a
database instead, like Jerry suggested.

Here's another idea - what is your XML being used for? If you are
generating your page content from the XML, maybe you should think about
caching the end result of your index.php to static HTML and updating
this cache when the XML is changed. If you feel PHP is a performance
hit, why not bypass it entirely if the end result will always be
essentially the same?
Jeremy
Jun 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
44076
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
2
2286
by: Chuck Ritzke | last post by:
Hi all, I am getting an intermittant error after uploading a project from my development machine. I click on a link which opens an aspx page that, upon page load, reads a very small amount of data from an MS Access database, using ODBC and a stored query. There is no problem on my development machine. On the production server though, I get the intermittant error shown below. If I click back and forth between the problem page and the...
9
6770
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger values, an example would be "AA" in EBCDIC hex wouldgive me the value of 63 in decimal (ASCII) when...
6
20021
by: HaggMan | last post by:
I'm creating a page that: - accepts user input in whatever language - saves that input to a file - reads the file and displays the original input The following code successfully writes the user input to a file (when I open the file, it's in the correct font), but I can't get PHP to read the file and display the correct characters. HTML --------------- Form
1
5678
by: Andrea Gavana | last post by:
Hello NG, that may sound a silly question, but I didn't find anything really clear about the issue of reading unformatted big endian files with Python. What I was doing till now, was using Fortran to read those files and compile this Fortran extension using F2PY. Now that it seems that no possible combinations of Fortran/C compilers actually *work* with Python 2.4 on Windows XP, I was trying to translate the Fortran subroutine to...
1
6499
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
0
3005
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from HRESULT: 0x800A03EC Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details:...
6
3528
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features to an old program that I wrote in delphi and it's a good opportunity to start with c++.
11
3818
by: itdevries | last post by:
Hi, I'm trying to convert some char data I read from a binary file (using ifstream) to a float type. I've managed to convert the int types but now I need to do the float types as well but it doesn't seem to work. The code below is what I'm trying to use. Anyone see any obvious errors? or have any hints/pointers? regards, Igor float floatRead = 0;
0
8801
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9015
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7953
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2110
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.