Page 1 of 1

Generating XML Files with PHP with Multiple HTTP Requests

Posted: Sun Feb 01, 2009 12:02 pm
by Randwulf
I need to generate XML logs for users from several HTTP requests that PHP can then parse.

It would work sort of like this:

On each request, PHP would check if the file the user is trying to log to already exists or not. If it doesn't, PHP would create the XML file and write this to it:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?><log>
Then, on each subsequent request, it would add

Code: Select all

<l>insert whatever here</l>
('l' would stand for line)

The problem is closing the parent tag, <log>. I'd rather not have my users have to tell the server to close the log for them, so I'm looking for ways to do one of the following:

A. Leave out the parent tags
B. Have PHP write </log> to the file after a certain period of inactivity
C. Something else

I'm thinking that B would probably be a good way to do this (if A isn't possible), but I'm not sure if PHP has that capability. Does PHP have timers or any other way of doing this? Thanks, I hope I was clear enough.

Re: Generating XML Files with PHP with Multiple HTTP Requests

Posted: Sun Feb 01, 2009 3:56 pm
by infolock
SimpleXML can do this for your (see adding child).

you can also query the XML file and do your checks from there..