Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Question about speed of 3 functions


ranma's Avatar
Member
0 0

For my cms I'm using an xml database to hold all the info for 1) global variables and 2) each individual page. The question is: When a user edits a page though the interface, the code will edit the xml to put in the right values for everything. When you want to see a page, the page opens up the template for the website, opens up the xml file with the info, and fills it in. So the question actually is: Should I save the xml file with the info and hard-code each page for faster loading (this way through the interface the xml is changed and the page re-hardcoded again), or should I just save the xml file and let each page open up the xml each time it's opened up to get its variables? Advantage of hard-coding the pages based on xml template: Faster page loading/less server strain Advantage of using xml each time: If someone wants to personally change some code, they can change the xml. If the other method is used if he changes the html only, when the interface is used the xml will override previous changes he has made manually to html.

So really, it boils down to, is opening up a simpleXML file much more resource intensive than using include(). If it's not, then I might as well use the xml opening each time, because it's not worse than include and it ensures no one will override data.

If I'm confusing, I can post a code snippet.

Also, is fopen slow? As in slower than include?


ynori7's Avatar
Future Emperor of Earth
0 0

Alright, that wasn't very clear. Let me reword it and see if I understand correctly. In both cases you want to use XML files to store your global variables.

Case 1: The pages all have the values programmed into them, and these values get updated from the XML all at once when you tell them to.

Case 2: The pages each access the XML file every time they're loaded for real-time updates.

If that's what you meant, I'd go with case 1. It's only necessary to update the files when a change has been made. It's more efficient.

EDIT:typo


ranma's Avatar
Member
0 0

Yup! That's what I meant. However, that means if someone goes into the html manually and changes it, next time the interface is used the xml will override his handmade changes.

Would you say case 1 is much more efficient;)? Or would case 2 not be too bad.


ynori7's Avatar
Future Emperor of Earth
0 0

ranma wrote: Would you say case 1 is much more efficient;)? Or would case 2 not be too bad. Maybe, maybe not. But case 2 is needlessly inefficient. There's not much gain from reloading the file every time you access a page. In fact, I think if you have a large number of people accessing your site, it could place extra strain on the server. It depends on how much data is being read from the file.


ranma's Avatar
Member
0 0

Is it worse than an include though? And I mean loading no more than around 20 KB of data.

Edit: Well, really it should be no more strain than running a query on a db, since xml is also used as flatfile databases.


ghost's Avatar
0 0

If you can open the XML file as little as possible I think it would take some strain off the server.

If I got the whole thing correctly, the problem is that if a user decides to edit the HTML instead of XML, it will be overridden either always or only when you tell it too? Then I think it is better to only override it when you want it to, and clearly state that it is recommended to change the XML instead of HTML.


ynori7's Avatar
Future Emperor of Earth
0 0

ranma wrote: Edit: Well, really it should be no more strain than running a query on a db, since xml is also used as flatfile databases. SQL is has a lot of optimizations built into it.


p4plus2's Avatar
Member
0 0

ranma wrote: Is it worse than an include though? And I mean loading no more than around 20 KB of data.

Edit: Well, really it should be no more strain than running a query on a db, since xml is also used as flatfile databases.

Why not test it out? Benchmark each about a thousand times and average it out… Yeah this is extra work but it will get you the most precise answer. My assumption is that SQL will be the victor(pgSQL if I had to pick which type of SQL). I would link you to benchmarks online, however those are often misleading due to different configurations.


ranma's Avatar
Member
0 0

Thanks everyone. P4plus, I'll do that.