HDFilmMaker2112 Posted June 10, 2012 Share Posted June 10, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/263927-generating-retrieving-and-storing-xml-filedata/ Share on other sites More sharing options...
trq Posted June 10, 2012 Share Posted June 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263927-generating-retrieving-and-storing-xml-filedata/#findComment-1352555 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 10, 2012 Author Share Posted June 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263927-generating-retrieving-and-storing-xml-filedata/#findComment-1352559 Share on other sites More sharing options...
trq Posted June 10, 2012 Share Posted June 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263927-generating-retrieving-and-storing-xml-filedata/#findComment-1352579 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 10, 2012 Author Share Posted June 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263927-generating-retrieving-and-storing-xml-filedata/#findComment-1352668 Share on other sites More sharing options...
ignace Posted June 10, 2012 Share Posted June 10, 2012 XML is not faster than MySQL. And with 40000 queries your XML solution will completely bog down your server while MySQL would only be getting warmed up. Quote Link to comment https://forums.phpfreaks.com/topic/263927-generating-retrieving-and-storing-xml-filedata/#findComment-1352671 Share on other sites More sharing options...
ignace Posted June 10, 2012 Share Posted June 10, 2012 If you have trouble setting up a DB schema for friend lists then take a look at: http://stackoverflow.com/questions/4674005/setting-up-a-friend-list-in-mysql Quote Link to comment https://forums.phpfreaks.com/topic/263927-generating-retrieving-and-storing-xml-filedata/#findComment-1352677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.