Generating XML Files with PHP with Multiple HTTP Requests

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Generating XML Files with PHP with Multiple HTTP Requests

Post 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.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Generating XML Files with PHP with Multiple HTTP Requests

Post by infolock »

SimpleXML can do this for your (see adding child).

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