Jump to content

Generating, retrieving, and storing XML file/data


HDFilmMaker2112

Recommended Posts

I know of the SimpleXML extension in PHP. But I'm looking for a bit of an example on how it would be put to use.

 

I would be generating a XML file from a database and then saving that file to the server. Are there any examples of this is actually done with SimpleXML?

 

An example of what I would probably be generating:

<news_feed>
<status_update>
	<user>User 432612</user>
	<message>This is a test message.</message>
	<date>6/9/2012 at 3:00 PM</date>
	<comment>Comment 1</comment>
	<comment>Comment 2</comment>
	<comment>Comment 3</comment>
	<comment>Comment 4</comment>
	<comment>Comment 5</comment>
</status_update>

<status_update>
	<user>User 423172</user>
	<message>This is a test message.</message>
	<date>6/9/2012 at 12:00 PM</date>
	<comment>Comment 1</comment>
	<comment>Comment 2</comment>
	<comment>Comment 3</comment>
	<comment>Comment 4</comment>
	<comment>Comment 5</comment>
</status_update>

<status_update>
	<user>User 441422</user>
	<message>This is a test message.</message>
	<date>6/9/2012 at 9:00 AM</date>
	<comment>Comment 1</comment>
	<comment>Comment 2</comment>
	<comment>Comment 3</comment>
	<comment>Comment 4</comment>
	<comment>Comment 5</comment>
</status_update>

<status_update>
	<user>User 434212</user>
	<message>This is a test message.</message>
	<date>6/7/2012 at 6:00 PM</date>
	<comment>Comment 1</comment>
	<comment>Comment 2</comment>
	<comment>Comment 3</comment>
	<comment>Comment 4</comment>
	<comment>Comment 5</comment>
</status_update>
</news_feed>

 

 

From there, how would I retrieve the file and read it? I'd be looking to load the file in my login.php page (just a processing page, nothing is shown here); then store that data some how for display on the page the user gets sent after the login page. If I've read write, I would need to store the XML as a string in order to store some where PHP can use it later. If so, how would I then get the data out of it?

Link to comment
Share on other sites

The first question I have to ask is why do you need the xml file? From your description, it seems an unnecessary step in the process.

 

Social Networking site. I'm figuring it would be less resource intensive to write a XML file of every bodies news feeds, instead of querying the database every single time they reload their news feed.

 

So say a user posts a status update, and they have 4000 friends, that update would be sent to those 4000 XML files. As opposed to say those 4000 people at some point loading their news feed page say 10 times each in any given browsing session; that's up to 40,000 possible database queries; instead of 1 query and 4000 xml file writes.

Link to comment
Share on other sites

I'm figuring it would be less resource intensive to write a XML file of every bodies news feeds

 

I haven't tested it, but I would figure that guess-timation would be incorrect. Databases are made for storing and retrieving data fast.

Link to comment
Share on other sites

It just seems like a logistical nightmare to run these via database queries.

 

I'd have to query the "connections" table to generate the users friends list, then pull all their friends status updates, then somehow order them in chronological order, since each friends status updates would be pull individually.

 

So I'd have iterate through 4000 queries in to the status updates table, and them somehow in PHP cobble them together in the correct order.

 

Then on top of all this, we'd have introduce the comments tables which would need to run queries for each and every status update.

 

So 4000 friends with 10 status updates each, would probably put the amount of queries at 40,000 then multiple by 10 times for the rough amount of times each user might come back to their news feed in any given browsing session. I'm at 400,000 queries for one user in a matter of an 30 minutes or so.

 

 

Would it not be better to produce the output on writing, not trying to read it dynamically? There will be significantly more reads then writes; Probably 100 to 1 or more.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.